CSC 271
Homework 3

Assigned 12 Oct
Due 9 Nov

Write a C or C++ program named "heads" which prints out the first line(s) of each of the files it is given as arguments.

The basic version of the program simply takes a list of filenames on the command line and prints the first line of each one to stdout. If one of the files is not found, print an informative error message (e.g. "File 'foo.snark' not found.") to stderr and go on to the next filename.

The more advanced version adds an option to allow the user to specify how many lines of a file to print: if the user gives a "-7" option, the program will print the first seven lines, rather than just the first line, of all files from then on. For example,

heads foo -3 snark -5 boojum beeblebrox
would print out the first line of foo, the first three lines of snark, the first five lines of boojum, and the first five lines of beeblebrox (assuming all four of those files actually exist).
Last modified: Fri Oct 12 10:16:58 EDT 2007
Stephen Bloch / sbloch@adelphi.edu