C program to copy the contents of one file to another
#include<stdio.h> #include<conio.h> void main()
{
FILE *fs,*ft;
char ch,fname1[20],fname2[20]; printf("\n Enter source file name:"); gets(fname1);
printf("\n Enter destination file name:"); gets(fname2);
fs=fopen(fname1,"r"); ft=fopen(fname2,"w"); if(fs==NULL||ft==NULL)
{
printf("unable to open"); exit(0);
}
do
{
ch=fgetc(fs); fputc(ch,ft);
}while(ch!=EOF); fcloseall();
printf("\nFile copy operation performed successfully");
}
Output
Enter source file name: 1.c Enter destination file name: 2.c
File copy operation performed successfully
Comments
Post a Comment