Guest User

Untitled

a guest
May 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. FILE *fs1, *fs2, *ft;
  7.  
  8. char ch, file1[20], file2[20], file3[20];
  9.  
  10. printf("Enter name of first filen");
  11. gets(file1);
  12.  
  13. printf("Enter name of second filen");
  14. gets(file2);
  15.  
  16. printf("Enter name of file which will store contents of the two filesn");
  17. gets(file3);
  18.  
  19. fs1 = fopen(file1, "r");
  20. fs2 = fopen(file2, "r");
  21.  
  22. if (fs1 == NULL || fs2 == NULL)
  23. {
  24. perror("Error ");
  25. exit(EXIT_FAILURE);
  26. }
  27.  
  28. ft = fopen(file3, "w");
  29.  
  30. if (ft == NULL)
  31. {
  32. perror("Error ");
  33. exit(EXIT_FAILURE);
  34. }
  35.  
  36. while ((ch = fgetc(fs1)) != EOF)
  37. fputc(ch, ft);
  38.  
  39. while ((ch = fgetc(fs2)) != EOF)
  40. fputc(ch, ft);
  41.  
  42. printf("The two files were merged into %s file successfully.n", file3);
  43.  
  44. fclose(fs1);
  45. fclose(fs2);
  46. fclose(ft);
  47.  
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment