Issued on: Tuesday 1:00am, March 20, 2007.
Due by: Monday midnight, April 9, 2007.
This assignment is to encourage you to do exercise on the dynamic data structure in C: the linked list , and on shell programming under UNIX. Since it will involve many important functions and commands, we will count it as two assignments. Therefore, it is our last assignment in this class and its total score is 20%.
Problem 1 (12%):
Write a program wordStat in C to do statistics on the words and the line numbers on which they appear in a text file. For example, given a text file named SonnetOftheMoon.txt, your program will generate the summary as in the output.txt by executing
wordStat < SonnetOftheMoon.txt.
Please notice that, the words are listed in ascending alphabetical order, and the line numbers are listed in ascending numerical order. All the words are converted to lower case for easy comparison. A line length can be defined to hold 255 chars.
The function readword.c is provided to you here for reading in a text file word by word from standard input until an end of file (EOF) is reached. Please refer to the comments for the detail usage.
*Note: You are required to use a Makefile and header file(s) for this program.
Problem 2 (8%):
- (1) Write a shell program in the current directory,
to look for every subdirectory containing a Makefile with a clean target;
to collect the names and the relative paths of these directories; and
to generate a Makefile in the current directory, with
-- a target clean to execute all the clean target of these Makefiles; and
-- a target backup to create a compressed archive of the current directory.
- (2) Write a shell program using sed to extract a set of lines (for example, from 5 to 10) from a file.
- (3) Write a shell program to reverse the order of a list of command line arguments.