Homework 4: A better cat

Homework is important practice for you, but it’s not graded so you don’t have to submit it.

Overview

The fourth homework assignment deals with an improved version of the cat command. Well, improved compared to our earlier version in any case, it’s still not close to the real cat.

The Program

The 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 one, two, three that contain the strings ONE, TWO, THREE:

$ 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, cat will still read from standard input as in our original version.

Hints

Deliverables

You should have a cat.c with the new features, one (or more!) test scripts, plenty of test cases, and a Makefile that builds cat by default and has clean and test targets. Of course the program should compile without warnings and you should have a way to use valgrind as part of testing.

Things to look into…

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!