Homework is important practice for you, but it’s not graded so you don’t have to submit it.
The fourth homework assignment deals with an improved version of the
Well, improved compared to our earlier version in any case, it’s
still not close to the real
cat program we wrote in lecture simply copies standard input to
standard output one character at a time.
It turns out that copying data like that is not the actual purpose of
cat at all: the
cat command is supposed to concatenate files.
Imagine we have three files
three that contain the
$ cat one ONE $ cat two TWO $ cat three THREE $ cat one two three ONE TWO THREE $ cat one two three >result $ cat result ONE TWO THREE
As you can see, the “new and improved” command can be given a sequence
of paths; it will read the files in the order given and copy the contents
of each, character-by-character, to standard output.
If we redirect standard output to a new
result file, that file will
contain the “concatenated” contents of the given files.
Note that if no paths are given as command line arguments,
still read from standard input as in our original version.
stdinis a stream just like a file you open for reading with
fopen. Your new
catshould not have to deal with copying from
stdinany differently than with copying from an actual file.
mainanymore. Seriously. What might be useful? A function to print an error message and
EXIT_FAILURE. A function to copy from one stream to another. Probably more.
grephomework. You should really spend the time to figure out how you can deal with the exit status of
catfrom the test script and how you can verify that the correct error messages are given on
You should have a
cat.c with the new features, one (or more!) test
scripts, plenty of test cases, and a
Makefile that builds
default and has
Of course the program should compile without warnings and you should
have a way to use
valgrind as part of testing.
Nothing to “look into” for this assignment, you pretty much “just” have to put all the pieces we’ve learned so far together into a nice package. But nobody is saying that it’s going to be easy. Good luck!