C Programming Tutorial

Advertisements

Write a program to copy one file to another in C



       #include<stdio.h>
       #include<conio.h>
       #include<process.h>

       void main()
       {
              FILE *fp1,*fp2;
              char ch;
              clrscr();

              fp1 = fopen("file1.txt","r");
              fp2 = fopen("file2.txt","wt");
              
              while((ch = fgetc(fp1))!=EOF)
                     fputc(ch,fp2); 

              fseek(fp,0,SEEK_SET);

              printf("\nAfter copying, data in file 2\n ");

              while((ch = fgetc(fp2))!=EOF)
                     printf("%c",ch);

              fclose(fp1);               
              fclose(fp2);               

              getch();
       }




Advertisement