Answer to Question #208757 in C for Swetha

Question #208757

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


1
Expert's answer
2021-06-20T08:10:41-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS