Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your job is to write several C programs performing operations on text files. Write a C program mergeSort.c that accepts three strings as parameters from

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Your job is to write several C programs performing operations on text files. Write a C program mergeSort.c that accepts three strings as parameters from the command line in main). These three strings are names of three files with the first two files containing each a sorted list of numbers separated by spaces. The program performs the following operation: a open the first two files as input files for reading data in text mode b. create a new text file as the output file using the third string as the file name c. read from the first file a number and store it in n1 d. read from the second file a number and store it in n2 e. append the smaller of the two numbers to the output file f. read the next number from the input file and then if n1 was smaller, read from the first file the next number and put it in n1 if n2 was smaller, read from the second file the next number and put it in n2 g. continue with step e h. if in step f. the input file contains no more numbers, i.e. the end of the file was reached append the remaining numbers of the other file to the output file i. close all files and terminate the program Your main function should take command line arguments. int main(int argc, char argvil Where argc is the amount of argument passed in and argv is an array of string which contains the arguments. So argv[1] is the first argument, etc Use feof to check the end of file; use fprintf to write to file and fscanf to read from file There is a special case in step c. and d. above. If either the first file or the second file contains no numbers, i.e. the file is empty, append numbers from the corresponding second or first file to the output file, close all files, and terminate. Your program implements the classic merge operation of a merge sort using two smaller lists of already sorted numbers to generate a complete list of sorted numbers Example command line: mergeSort numbers1.txt numbers2.txt sortedNumbers.txt Two list files were provide for the testing purpose

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

What is the best conclusion for Xbar Chart? UCL A X B C B A LCL

Answered: 1 week ago