Write a file program to merge the content of source1.txt file and
source2.txt file to destination.txt file and display the fallowing from
the destination file.
• Count number of lines
• Count number of words
• Count the frequency of occurrence of the words
source1.txt
Hello Welcome to KSRCT
Hello Welcome to KSRCE
source2.txt
Hello Welcome to KSRIET
Hello Welcome to KSRCAS
Destination.txt
Hello Welcome to KSRCT
Hello Welcome to KSRCE
Hello Welcome to KSRIET
Hello Welcome to KSRCAS
Output display after reading from destination.txt file
Number of lines : 04
Number of words: 16
Frequency of words
Hello appears 4 times
Welcome appears 4 times
to appears 4 times
KSRCT, KSRCE, KSRIET and KSRCAS appears 1 times
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *f1 = fopen("source1.txt", "r");
FILE *f2 = fopen("source2.txt", "r");
FILE *f3 = fopen("destination.txt", "w");
char ch;
while ((ch = fgetc(f1)) != EOF)
fputc(ch, f3);
while ((ch = fgetc(f2)) != EOF)
fputc(ch, f3);
fclose(f1);
fclose(f2);
fclose(f3);
return 0;
}
Comments
Leave a comment