Tuesday, 30 September 2014

Program to copy the content of one file into another file in C

#include<stdio.h>

void main()
{
 FILE *f1,*f2,*f3;
 char fn[10],a[1000],buff[1000];
 int i,j;
     
  printf("Enter the file name::");
  gets(fn);
 
     f1 = fopen(fn,"w");
   printf("Enter the content of the File::");
     gets(a);
     fprintf(f1,"%s",a);
 fclose(f1);

    f2 = fopen(fn,"r");
    f3 = fopen("fat.txt","w");
     while( fgets(buff,1000,f2) != NULL )
        fprintf(f3,"%s",buff);
 fclose(f2);
 fclose(f3);
  printf("The content of the File::");
    f3 = fopen("fat.txt","r");
   while( fgets(a,1000,f3) != NULL )
     {
       printf("%s",a);  
     }
 printf("\n");
 fclose(f3);
}

No comments:

Post a Comment