Virajsinh

FileHandling_3

Nov 17th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. //Make Two File Data Copy Another File Like Merge Data
  2.  
  3. #include<conio.h>
  4. #include<stdio.h>
  5.  
  6. void main()
  7. {
  8.     FILE *fp1, *fp2,* fp3;
  9.     char ch;
  10.  
  11.     clrscr();
  12.  
  13.     //Create FirstFile.txt in C:/TurboC3/BIN
  14.     fp1=fopen("File1.txt","r");
  15.     if(fp1==0)
  16.     {
  17.         printf("\n First File Opening Error");
  18.     }
  19.  
  20.     //Create SecondFile.txt in C:/TurboC3/BIN
  21.     fp2=fopen("File2.txt","r");
  22.     if(fp2==0)
  23.     {
  24.         printf("\n Second File Opening Error");
  25.     }
  26.  
  27.     fp3=fopen("Student.txt","w");
  28.     if(fp3==0)
  29.     {
  30.         printf("\n Third File Creating Error");
  31.     }
  32.  
  33.     ch=fgetc(fp1);
  34.  
  35.     //Copy FirstFile Data in ThirdFile.txt
  36.     while(ch!=EOF)
  37.     {
  38.         fputc(ch,fp3);
  39.         ch=fgetc(fp1);
  40.     }
  41.  
  42.     //FirstFile.txt Copy After Add New Line
  43.     fputc('\n',fp3);
  44.     ch=fgetc(fp2);
  45.  
  46.  
  47.     //Copy SecondFile.txt Data in ThirdFile.txt
  48.     while(ch!=EOF)
  49.     {
  50.         fputc(ch,fp3);
  51.         ch=fgetc(fp2);
  52.     }
  53.  
  54.     //SecondFile.txt Copied in ThirdFile.txt
  55.     fcloseall();
  56.     printf("\n FirstFile And SecondFile Merged in ThirdFile");
  57.     getch();
  58.     }
Add Comment
Please, Sign In to add comment