Computer Systems Organization I - Prof. Grishman

Assignment #4

First write a C function

int getline (char line[], int maxlength)

which reads characters from standard input until a newline character ('\n') or the end-of-file (EOF) and stores into array line the first up to maxlength characters which were read, followed by a null ('\0') character.  The terminating newline should not be stored in line.  getline should return the length of the string stored in line, or -1 if it encounters an EOF.  You may assume that the final line will be terminated by a newline character (this is normally true for UNIX files, but not necessarily for files prepared under Windows).

Then write a main function which reads in a series of lines (using getline) and writes to standard output a single number, a count of the number of lines following the first line which are identical to the first line.  For example, if the file consists of
moo
quack
moo
quack
moo
the program should write '2'.

Submit your program (.c file) by email, as an attachment,  to me <grishman@cs.nyu.edu> and to the e-tutor, Andrew Montalenti <am1221@nyu.edu>, by one minute before midnight on Thursday, November 3rd. (Late assignments will be penalized 1/2 point for each day late, out of a total of 4 points.) Label your email "CSO Asgn 4".