Due: Wednesday, March 28
Things to note:
What to hand in:
Rewrite your homework 5a so that it uses C's command line arguments to input zero or more files names to process. If no arguments are given for the file names, default to all 21 input files.
Add the flag -s name, so that your program will print the statistics for the given name. For example:
hw5c -s Dianna names1900 names2000
will print out the rank, number and percentages of the name Dianna used in 1900, 2000, as well as the combined total stats of these two years. Modfiy your program so that it no longer hardcodes the names it looks for.
Add the flag --help, which prints out a Unix-like manual page informing the user how to use your program and its arguments. Also print this screen whenever improper input has been detected. Also, if there is a --help flag, it cancels out all others, i.e. help screen will be printed and nothing else.
Add the flag -r, which prints out the rank of the name searched (and total rank)
Add the flag -n, which prints out the usage number of the name searched (and total usage number)
Add the flag -p, which prints out the percentage of the name searched (and total percentage)
These 3 flags can combine at will and come in any order, i.e. -r -n -p is equivalent to -n -p -r, or -npr or -nrp, etc. Any or all of them may be omitted. If no flags are given, default is -rnp, and interactive (see below).
If no -s flag is given, then enter the interactive mode, where you will keep prompting the user for a name to search and report appropriate statistics for (according to the -r -n and -p flags), until the user ends the program by typing ^D.
You may assume that the list of file names is always last, i.e. the first non-flag argument you encounter is assumed to be the beginning of the list of file names. However, the flags themselves may come in any order. If --help is present, ignore all others.
Make sure you error-check your arguments thoroughly, i.e. illegal/badly-formated options, non-existent options. Remember that some flags are optional and some flags (--help) cancel out all others, and the order of flags should not matter. Your program should behave rationally no matter how unreasonable the input or the value of flags. Check out Unix utility programs to see examples of flag and error handling.
Remember that the unix wild star (*) will let you specify multiple file names that fit a certain pattern easily, for example:
hw5c -s Dianna names200*
will be expanded to:
hw5c -s Dianna names2000 names2001 names2002 names2003 names2004 names2005 names2006 names2007 names2008 names2009
by the shell for you. Using this feature to test might reduce tedious typing.
Continuing from the previous part, implement a further functionality so that your program is able to find all variations of a name and print the proper stats. For example, given "John", there are "Johnnie", "Johnathan", etc. Note that I am only asking for strict substring variations, not the smart variations such as recognizing Bill is short for William. However, do note that there are male and female variations, such as "Johnna" for "John".
For each variation, print out the proper stats as dictated by the flags and input files as before.
Implement the flag -v name for this. -v overwrites -s, if both were given.