Untitled
unknown
plain_text
a year ago
1.0 kB
7
Indexable
#include <stdio.h>
#include <stdlib.h>
void duplicateFile(const char *inputFile, const char *outputFile) {
FILE *input = fopen(inputFile, "r");
if (input == NULL) {
printf("Error: Unable to open the input file.\n");
return;
}
FILE *output = fopen(outputFile, "w");
if (output == NULL) {
printf("Error: Unable to open the output file.\n");
fclose(input);
return;
}
char tempBuffer[1024];
size_t readBytes;
while ((readBytes = fread(tempBuffer, 1, sizeof(tempBuffer), input)) > 0) {
fwrite(tempBuffer, 1, readBytes, output);
}
fclose(input);
fclose(output);
printf("File duplication completed successfully.\n");
}
int main() {
char inputFileName[100], outputFileName[100];
printf("Please provide the source file name: ");
scanf("%s", inputFileName);
printf("Please provide the target file name: ");
scanf("%s", outputFileName);
duplicateFile(inputFileName, outputFileName);
return 0;
}
Editor is loading...
Leave a Comment