File Operations in C

Task1

Write a program that joins the two sorted files to an output file such that the resulting file is also sorted. Your program should read the names of the files to be joined from the command line, as well as the name of the file which will store the joined content, as shown below:

ProgramName filename1 filename2 filenameOut

The files that your program will join contain floating point numbers sorted in increasing order. Your program should read from the input files and write to the output file appropriately so that the resulting file will also be sorted in increasing order.

In case one of the input files are not sorted in increasing order, your program should complain and exit, displaying an appropriate message.

You can test your code with different data files that are supplied.

Task2

Write a program that reads a given file containing floating point numbers and appends a summary line to the end of the file showing the count of numbers, the maximum number, the minimum number and a flag showing whether the file is sorted or not.
For data1.txt, the line will be like:
# 4 6.229683 0.586399 increasing
For data2_us.txt, the line will be like:
# 7 12.158343 0.279828 unsorted
The program should check whether last line of the file starts with the ‘#’ sign and update the line, in case it exists. Thus, after running the program with the same input file multiple times, there should exist only one summary line at the end of the file that starts with the ‘#’ sign.

Code1

 

Code2

 

Leave a Reply

Your email address will not be published. Required fields are marked *