Question
In C please 16.15 Lab 5: b Name this program merge.c - This program will take two arguments from the command-line which will be the
In C please
16.15 Lab 5: b
Name this program merge.c - This program will take two arguments from the command-line which will be the names of the two text files the program will read from.These text files contain a list of numbers each in ascending order. You'll open the text files and begin merging the two sets of numbers together until every unique number is printed to the screen once and in order. For example:
file1.txt | file2.txt |
---|---|
1 | 2 |
2 | 4 |
3 | 6 |
6 | 7 |
file3.txt: 1 2 5 7 9 10 11 13 15 17 19 20 21 24 25
file4.txt: 3 4 6 8 10 11 12 14 16 18 20
Note: make sure your input text files end with an empty newline, or the last number may be skipped. Lines must end with a newline character, according to the standards we follow.
Example executions:
./a.out file1.txt file2.txt 1 2 3 4 6 7
./a.out file3.txt file4.txt 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 24 25
Here is the solution in pseudo-code:
Read number1 from file1Read number2 from file2 While ( not EOF for file1 AND not EOF for file2 ) If number1 is less than number2 Print number1 and read the next number from file1 Else if number1 is greater than number2 Print number2 and read the next number from file2 Else (the numbers are the same) Print the number and read the next number from both files End while // at most one of the following two while statements will be true While( file1has not yet hit EOF) Print number1 and read the next number from file1 While( file2has not yet hit EOF) Print number2 and read the next number from file2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started