Write a C program to merge two files into a third file (i.e., the contents of the first file followed by those of the second are put in the third file).

Algorithm:

Step 1: Start
Step 2: open a empty file in write mode.
Step 3: if it is not end of file
Step 4: write data into that file.
Step 5: close the write mode operation
Step 6: repeat the above process for second file.
Step 7: now use concatenation operation to combine the files.
Step 8: the contents of the file will be displayed in the third file.
Step 9: Stop

Program:

#include<stdio.h>
 void concatenate(FILE *fp1, FILE *fp2, char *argv[], int argc);
 int main(int argc, char *argv[]){
   FILE *fp1, *fp2;
   concatenate(fp1, fp2, argv, argc);
   return 0;
 }

void concatenate(FILE *fp1, FILE *fp2, char **argv, int argc){
   int i, ch;
   fp2 = fopen("files", "a");
   for(i = 1; i < argc - 1; i++){
      fp1 = fopen(argv[i], "r");
      while((ch = getc(fp1)) != EOF)
      putc(ch, fp2);
   }
 }

Input & Output:

File1:
studentboxoffice.in.
File2:
This is Computer Programming Lab.
File 3:
studentboxoffice.in. This is Computer Programming Lab.