Homework is important practice for you, but it’s not graded so you don’t have to submit it.
The first homework assignment is writing a clone of the UNIX
No worries, it’s a simplified clone, it doesn’t have to support
all the features of the actual
But you should read the
man page for
wc anyway, just to see
what the real program can do in addition.
wc program reads from standard input. Once the input it over,
it prints the number of lines, words, and characters (bytes) the input
had to standard output. Here are two examples for how this works:
$ ./wc 0 0 0 $ ./wc Hi there! This is a test for you... 2 8 36
First I started the program and then immediately hit
CTRL-D to signal
end-of-file. Therefore the output is 0 lines, 0 words, and 0 characters.
Then I started the program and typed the two lines (hitting
twice in the process), then I typed
CTRL-D. There are 2 lines, 8 words
(meaning 8 stretches of characters not interrupted by white space, check
the definition of “word” in the
man page for
wc), and a total of 36
(If you’re confused why it’s 36, remember to count the invisible newline
characters as well!)
wcprogram formats the output line a bit differently, but you should follow our specification here and not theirs.
isspacefunction from the C standard library to decide whether a character is whitespace or not; don’t try to decide for yourself.
stdoutbut only the expected output as specified above.
At minimum, you should have a file
wc.c with your actual program code
Makefile that builds the
wc program with the correct compiler
The program should compile without warnings and produce no output other
than what is described above, in exactly that format.
Ideally you should only have to say
make to build, not
make wc but
we didn’t cover yet how to do it.
Ideally you should be able to say
make clean to remove the executable
make test to run test cases, but we didn’t cover yet how to do
The shell/terminal can be scripted, that’s a way to run several test
cases automatically. Again, we didn’t cover that yet, but if you want
to look ahead at basic shell scripting and think about how we could
combine it with I/O redirection and the
diff tool, that’s certainly
not wasted time.