Develop a C program to copy the content of one file and store that content in another file.
Runtime Input :
Good Morning
Output :
Good Morning
#include <stdio.h>
int main()
{
char* filename = "D://finput.txt";
char* filename2 = "D://foutput.txt";
char str[256];
FILE *mfile;
FILE *mfile2;
if((mfile = fopen(filename, "r"))==NULL)
{
perror("Error occured while opening file");
return 1;
}
if((mfile2 = fopen(filename2, "w"))==NULL)
{
perror("Error occured while opening file");
return 1;
}
while((fgets(str, 256, mfile))!=NULL)
{
fputs(str, mfile2);
}
fclose(mfile);
fclose(mfile2);
printf("\nFile %s copied to %s\n", filename, filename2);
return 0;
}
Comments
Leave a comment