Lab (0) - Character Counting

The original version of this lab is from Andrew Dalton for the CS2440 in Spring 2002. Modifications were made by Rahman Tashakkori for CS2440 in Summer 2004.
Create a directory lab0 under the 2440 directory and complete your program there.  If you do not have directory 2440 in your main directory, create that one first.

Write a program that takes a single command line parameter that specifies the name of a text file containing a list of words. The program should then read in that file and keep a running count of the number of times each character (includes alphabets, digits, special characters, blank space, etc) is used. The source for the words will be the following file: ~rt/2440/knuth.dat. Name your source file lab0.C.

Command Line Parameters

Command line parameters are simply parameters passed to an application when it is executed. You're familiar with this using such applications on cs as 'ls'.

ls -l myfile.cpp

Here, "-l" and "myfile.cpp" are both command line parameters to the program "ls."

For C++ to handle command line parameters, two parameters are passed to main. The first of these two parameters is a count of the number of parameters being passed. This variable is commonly named "argc" for "argument count." The second parameter passed to main is an array of C-strings that represent the passed parameters. This variable is commonly named "argv" for "argument vector." The name of the invoked application is always the first of these strings (and therefore, argc is always >= 1).

Let's look at an example:

 1 #include <iostream>
 3 int main(int argc, char* argv[]) {
 4     std::cout << "argc:  " << argc << std::endl;
 6     for (int i = 0; i < argc; ++i) {
 7         std::cout << "argv[" << i << "]: "
 8                   << argv[i] << std::endl;
 9     }
11     return 0;
12 }
And a sample of the output of this program:
> example hello there 2440!
argc:  4
argv[0]: example
argv[1]: hello
argv[2]: there
argv[3]: 2440!
You will use command line parameters to pass in the name of the file to read the word list from. You'll want to check the argc parameter to insure that the parameter was passed (argc > 1), then use the specified string as a filename.
The output from the program will be a list of the characters and a count of the number of times they appeared in the file.

You can see the output of a sample run here:  output.

Code Submission
Make sure you are in the directory lab0 under 2440.  I will grade the program that is stored in that directory.