This is an exercise in "coding to specifications." Following the Coding Guidelines for this Course, you are to write a C++ program which exactly mimics the Unix wc command.
Read the man page for the wc command, and experiment
with
it to make sure you understand what the program does. Then, write a
single source module named wc.cc
which performs exactly
the same operations as the wc command.
Use the getopt_long() function to process the following command line options:
Option | Interpretation | |
---|---|---|
-c or --chars | Print the number of characters only. | |
-l or --lines | Print the number of lines only. | |
-w or --words | Print the number of words only. | |
-L or --max-line-length | Print the length of the longest line only. | |
-? or --help | Print a "usage" message and exit. |
Options may be combined, so that "-c -w" (or -cw) will print the counts for both the number of characters and the number of words.
Note: if you use Forbin, which does not support the getopt_long() function, to test your program you will have to ignore the long versions of the options and process only the short versions (-c, -l, -w, and -L) using the getopt() function. Extra credit: write your code so it compiles without modification on either forbin or Linux.
./wc -lw file1 file2 file3 > out1 /usr/bin/wc -lw file1 file2 file3 > out2 diff out1 out2(The above diff command should produce no output.)
Follow the instructions in the Coding Guidelines web page for
creating a tar file of your "clean" project directory. For this
assignment, you will not be using make or rcs for project
management, so your tar file should contain just the following: your
project directory, which is to contain only the file named wc.cc and an
empty subdirectory named RCS
. There must be no other
files in the tar file.
When your assignment has been coded and tested on your linux virtual machine, send me an email message with the subject line, "CS-701: Assignment 2". Put your name and id number in the body of the message, and include your tar file as an attachment. You may send the project from any Unix system on which you have an email account. I will test your program on CygWin or, if that doesn't work, on Dijkstra. (If you send the assignment using the pine email program on linux, attach the tar file by typing Control-J while the cursor is in the heading part of your message.)
Submit the assignment to me using my account (vickery) on Dijkstra.