Develop a C program to copy the content of one file and store that content in another file
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *sourceFilePtr, *targetFilePtr;
char sourceFile[20];
char targetFile[20];
char letter;
printf("Enter source file: ");
gets(sourceFile);
sourceFilePtr = fopen(sourceFile, "r");
if (sourceFilePtr != NULL) {
printf("Enter target file: ");
gets(targetFile);
targetFilePtr = fopen(targetFile, "w");
while ((letter = fgetc(sourceFilePtr)) != EOF){
fputc(letter, targetFilePtr);
}
printf("File copied successfully.\n");
fclose(sourceFilePtr);
fclose(targetFilePtr);
}else{
printf("The file %s does not exist.\n",sourceFile);
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment