Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*На вход программы поступают имена трех
- файловНеобходимо записать содержимое
- первых двух файлов в третий в вперемешку*/
- /* program to merge two files
- and stores their contents in another file*/
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- FILE *fs1, *fs2, *ft;
- char ch, firstFile[20], secondFile[20], mergedFile[20];
- printf("Enter name of first file\n");
- gets(fileFile);
- printf("Enter name of second file\n");
- gets(secondFile);
- printf("Enter name of file which will store contents of two files\n");
- gets(mergedFile);
- fs1 = fopen(firstFile,"r");
- fs2 = fopen(secondFile,"r");
- if( fs1 == NULL || fs2 == NULL )
- {
- perror("Error ");
- printf("Press any key to exit...\n");
- getch();
- exit(EXIT_FAILURE);
- }
- ft = fopen(mergedFile,"w");
- if( ft == NULL )
- {
- perror("Error ");
- printf("Press any key to exit...\n");
- exit(EXIT_FAILURE);
- }
- while( ( ch = fgetc(fs1) ) != EOF )
- fputc(ch,ft);
- while( ( ch = fgetc(fs2) ) != EOF )
- fputc(ch,ft);
- printf("\n\nTwo files were merged into %s file successfully.\n",mergedFile);
- fclose(fs1);
- fclose(fs2);
- fclose(ft);
- return 0;
- }
- output
- Enter name of first file
- firstFile.txt
- Enter name of second file
- secondFile.txt
- Enter name of file which will store contents of two files
- mergedFile.txt
- Two files were merged into mergedFile.txt successfully
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement