Wednesday 14 December 2016

Write a program to copy a file into another file.

Q. Write a program to copy a file into another file?

/*   ###########################
     Girfa : Student Help
     for more program visit : http://girfahelp.blogspot.in/p/c-language.html
     copy a file content to another file
     ############################
*/
#include<stdio.h>
#include<conio.h>
void main()
{
     FILE *sfile,*dfile;
     char ch;
     int flag=1;
     clrscr();
     sfile=fopen("source.txt","r"); /* Source file */
     if(sfile==NULL)

     {
          printf("\nSource File Opening Error");
          flag=0;
     }
     dfile=fopen("new_file.txt","w"); /* Destination File */
     if(dfile==NULL)
     {
          printf("\nDestination  File Opening Error");
          flag=0;
     }
     if(flag==1)
     {
          while((ch=fgetc(sfile))!=EOF)
              fputc(ch,dfile);
          printf("\n\tFile copy Successfully");
     }
     fclose(sfile);
     fclose(dfile);
     getch();

}



No comments:

Post a Comment