Professional Documents
Culture Documents
Merge Files (454 Ece A)
Merge Files (454 Ece A)
TWO FILES
PRSENTED BY :
R.TEENA SREE
ECE-A
22R01A0454
MERGING
Merging two files means the content of any two
files (entered by the user at runtime) gets merged into the third
file in a way that the content of the first source file gets copied to
the target file, and then the content of the second source file gets
appended to the target file.
THINGS TO DO BEFORE THE
PROGRAM
• The program will ask for the two names of the file from
where the content is copied and then ask for the third file
name where both the files are concatenated and copied
there. If the third file is not present then the program will
automatically create a file with the entered name
LOGIC TO MERGE TWO FILES
TO THIRD FILE
#include
#include <stdlib.h>
void main()
clrscr();
gets(str1);
gets(str2);
gets(str3);
}
.
fp1 = fopen(str1, "r");
fp2 = fopen(str2, "r");
fp3 = fopen(str3, "w"); // Opening in write mode
if ((fp1 == NULL ) || ( fp2 == NULL) || (fp3 == NULL ))
{
printf("Error ");
exit(1);
}
while ((ch = fgetc(fp1)) != EOF)
.
{
fputc(ch, fp3);
}
while ((ch = fgetc(fp2)) != EOF)
{
fputc(ch, fp3);
}
printf(“MERGED SUCCESSFULLY”);
fclose(fp1);
fclose(fp2);
fclose(fp3);
getch();
}
OUTPUT:
AFTER :
microproject.txt :
Hello World!
This is RAGULA TEENA SREE !!!!