Name this program merge c The program uses two input files s
Solution
C program merg.c
#include <stdio.h>
int main(int argc, char *argv[] ) // Command line inputs to the program
 {
 FILE *fpA,*fpB; // file pointers for file A abd B
 int A,B,Ra,Rb; // variable decleration
 fpA = fopen(argv[1],\"r\"); // Opening first file for reading
 fpB = fopen(argv[2], \"r\"); // Opening second file for reading
 fscanf(fpA,\"%d\",&A); // frist reading from file A
 fscanf(fpB,\"%d\",&B); // reading from file B
 while(!feof(fpA) && !feof(fpB)) // loop til end of file of any file
 {
 if(A == B) // both are equal means print one
 {
 printf(\" %d\",A);
 Ra = 1; Rb = 1;
 }
 else if(A < B) // A is smaller means print A
 {
 printf(\" %d\",A);
 Ra = 1; Rb = 0;
 }
 else // else print B
 {
 printf(\" %d\",B);
 Rb = 1; Ra = 0;
 }
 if(Ra == 1)fscanf(fpA,\"%d\",&A); // reading from file A
 if(Rb == 1)fscanf(fpB,\"%d\",&B); // reading from file B
 }
 // checking and printing the ramining values in the variables while exit of loop
 if(A < B)printf(\" %d %d\",A,B);
 if(A > B) printf(\" %d %d\",B,A);
 if(A == B) printf(\" %d\",A);
 // printing the remaining elements in the file A if any
 if(!feof(fpA))
 {
 while(!feof(fpA))
 {
 fscanf(fpA,\"%d\",&A);
 printf(\" %d\",A);
 }
 }
 // printing the remaining elements in the file B if any
 if(!feof(fpB))
 {
 while(!feof(fpB))
 {
 fscanf(fpB,\"%d\",&B);
 printf(\" %d\",B);
 }
 }
 printf(\"\ \");
 return 0;
 }
A.txt
-812 -99 1 44 99 1831 2016
B.txt
-407 -55 -22 1 99 1831 2015
OUTPUT: Compailing and running
sh-4.3$ gcc -o main *.c sh-4.3$ ./main A.tex B.tex -812 -407 -99 -55 -22 1 44 99 1831 2015 2016 sh-4.3$
![Name this program merge. c- The program uses two input files specified on the command line, via argv[1] and argv [2]. Both files contain unique integer in asce  Name this program merge. c- The program uses two input files specified on the command line, via argv[1] and argv [2]. Both files contain unique integer in asce](/WebImages/32/name-this-program-merge-c-the-program-uses-two-input-files-s-1093782-1761576348-0.webp)
![Name this program merge. c- The program uses two input files specified on the command line, via argv[1] and argv [2]. Both files contain unique integer in asce  Name this program merge. c- The program uses two input files specified on the command line, via argv[1] and argv [2]. Both files contain unique integer in asce](/WebImages/32/name-this-program-merge-c-the-program-uses-two-input-files-s-1093782-1761576348-1.webp)
