#include <stdio.h>
#include <stdlib.h>
int main()
{
// please enter the file address of your text file which two you want to merge
FILE *fp1 = fopen("F:/file1.txt", "r");
FILE *fp2 = fopen("F:/file2.txt", "r");
// file 3 is the file in which you want merge the data of the two above files
FILE *fp3 = fopen("F:/file3.txt", "w");
char c;
if (fp1 == NULL || fp2 == NULL || fp3 == NULL)
{
puts("Either file is not available or there there is something incorrect. Please check it...");
exit(0);
}
// copy of the file 1 data to the file 3
while ((c = fgetc(fp1)) != EOF)
fputc(c, fp3);
// copy of the file 2 data into the file 3
while ((c = fgetc(fp2)) != EOF)
fputc(c, fp3);
printf("The data of the file1 and file2 has been merged.");
fclose(fp1);
fclose(fp2);
fclose(fp3);
return 0;
}
Comments
Leave a comment