File Copy

#include <stdio.h>

int main() {
    // File copy
    FILE *sourceFile, *destinationFile;
    char buffer[100];

    sourceFile = fopen("source.txt", "r");
    destinationFile = fopen("destination.txt", "w");

    if (sourceFile != NULL && destinationFile != NULL) {
        while (fgets(buffer, sizeof(buffer), sourceFile) != NULL) {
            fputs(buffer, destinationFile);
        }
        fclose(sourceFile);
        fclose(destinationFile);
        printf("File copied successfully.\n");
    } else {
        printf("Unable to open files.\n");
    }

    return 0;
}
chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website