#! /bin/sh for f do wc $f doneLook up the wc command using man wc. Test this script by typing it into a file such as "count_stuff", making it executable (use chmod +x count_stuff), and typing ./count_stuff count_stuff count_stuff as a command. Be sure you understand the output and how the script works.
In additon to the lines the above script produces, your program is to output one more line, which gives the total number of lines, words, and characters in all files, plus one more line telling the number of files processed successfully. Except for the very last line, the output of your program should exactly match the output of the wc command when multiple file names are entered on the command line.
Your program is also to output an appropriate error message if any of the files named on the command line don't exist or otherwise cannot be read, but except for the requirement to use perror() (see below), the format of these error messages does not have to match the error messages produced by wc exactly.
Your program must be coded according to the [ Coding Guidelines ] for this course. This includes the requirement that the program must compile and link with no error or warning messages, in addition to running correctly. It also includes the requirement that the program must be properly documented. However, you are not expected to use either the RCS or make development tools for this assignment.
precis.cc
, which you are to compile into an executable file
named precis
using the following command line:
g++ -g -Wall -Wwrite-strings precis.cc -o precisThe above command must produce no warning or error messages.
Although you will not use RCS for this assignment, the first line of precis.cc must be:
// $Id$Your code must use the following functions to perform the indicated tasks:
fopen() | To open each file named on the command line. |
perror() | To print any error messages. |
fgets() | To read each line of a file. |
strlen() | To count how many characters there are in a line. (fgets() returns each line of the file as a string.) |
strtok() | To divide each line into "words" (tokens). Just count how many times strtok() is successful at getting a token out of a line. |
If the user types the name of a "binary" file as one of the command line arguments, your program does not have to do anything special about it; just assume that all files are text files.
Test your program carefully before creating the tar file and submitting it. (Don't worry about making the project directory "clean" for this assignment as called for in the coding guidelines.) You should use the following procedure to test your program:
% ./script a_file b_file c_file > script.out % ./precis a_file b_file c_file > precis.out % diff script.out precis.outHere, a_file, b_file, and c_file are the names of text files, some of which might not exist or might be unreadable by the user. Substitute an appropriate set of file names when testing. "./script" is the script given to you at the beginning of the Requirements section of this handout. The diff command prints out those lines that are different between two files; the only lines that it should print are the two extra lines that precis prints compared to the script.