As usual, keep a log in the file lab6.txt of what you do in the lab so that you can reproduce the results later. This should not merely be a transcript of what you typed: it should be more like a true lab notebook, in which you briefly note down what you did and what happened.
For this laboratory, you will implement the same program using both buffered and unbuffered I/O, and compare the resulting implementations and performance.
Rewrite the binsortu program you wrote for Homework 5 so that it uses system calls rather than <stdio.h> to read standard input and write standard output. If standard input is a regular file, your program should initially allocate enough memory to hold all the data in that file all at once, rather than the usual algorithm of reallocating memory as you go. However, if the regular file grows while you are reading it, your program should still work, by allocating more memory after the initial file size has been read.
Your program should do one thing in addition to the Homework 5 program. If successful, it should use the fprintf function to output a line of the following form to standard error before finishing:
Number of comparisons: 23451
where the integer "23451" is replaced by the actual number of comparisons done by your program, and where a "comparison" is a binary comparison between two input lines. The line should be worded exactly as above: for example, it should contain exactly three spaces. It should be terminated with a newline.
Call the rewritten program binsortuu. Measure any differences in performance between binsortu and binsortuu using the time command. Run your program on inputs of varying numbers of input lines, and estimate the number of comparisons as a function of the number of input lines.
Submit the following files.
All files should be ASCII text files, with no carriage returns, and with no more than 200 columns per line. The C source file should contain no more than 132 columns per line. The shell commands
expand lab6.txt binsort.txt | awk '/\r/ || 200 < length' expand catb.c catu.c binsortuu.c | awk '/\r/ || 132 < length'
should output nothing.