C Program To Copy The Contents Of A One File To Another File


#include< stdio.h >
#include< conio.h >
#include< stdlib.h >
void main()
 {
FILE *fs,*ft;
char ch;
clrscr();
 fs = fopen("file1.txt","r");
 if(fs==NULL)
  {
 printf("Cannot open source file ! Press key to exit.");
 getch();
 exit(0);
  }
ft = fopen("file2.txt","w");
 if(ft==NULL)
{
printf("Cannot copy file !");
 fclose(fs);
 getch();
 exit(0);
 }
while(1)
 {
ch = getc(fs);
if(ch==EOF)
{
 break;
}
else
putc(ch,ft);
}
printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------

File copied successfully!

0 comments :