Write a C program to copy the contents of one file into another file.
Solution:
Output:



Before executing this program, create source.txt file at the same location where this program is located.
After creating source file, execute this program, you will get a message 'File copied..'.
Now, if you access the location where your program & source file are located, you will get backup.txt with same content as in source file.
Solution:
#include<stdio.h>
int main()
{
int ch;
FILE *fp,*fq;
fp=fopen("source.txt","r");
fq=fopen("backup.txt","w");
if(fp==NULL||fq==NULL)
printf("File does not exist..");
else
while((ch=fgetc(fp))!=EOF)
{
fputc(ch,fq);
}
printf("File copied.....");
return 0;
}
Output:



Before executing this program, create source.txt file at the same location where this program is located.
After creating source file, execute this program, you will get a message 'File copied..'.
Now, if you access the location where your program & source file are located, you will get backup.txt with same content as in source file.


