CS 200 - Lab 13

Input character classifier

Write a program that reads each character from standard input (i.e., the input typed by the user) and determines which of the following categories the character belongs to:

Your program should keep a running count of the number of characters seen falling into each category.

When the user closes the standard input by typing Control-Z followed by Enter, the program should print a summary of how many characters were counted in each category.

Example run (user input in bold red):

Now is the winter of our discontent.
Four score and seven years.
OK, l8r dude.
^Z
The input contained:
4 upper case letters
55 lower case letters
1 digits
15 whitespace characters
5 characters that didn't fall into the above categories

Getting started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download lab13.zip.  Import it into Visual Studio (File->Import...).

Add your code to the source file called Classifier.c.

Hints

The program should contain a loop that looks something like this:

while (!feof(stdin)) {
int ch;

ch = getchar();

if (ch >= 0) {
/* classify the character whose character code is stored in ch */
}
}

In the above loop, the condition

!feof(stdin)

yields a true value if there are more characters to read from the keyboard, false otherwise.

You can determine whether or not a character value is a "whitespace" character (space, tab, newline, etc.) by testing the condition

isspace(ch)

where ch is the value of the character you want to test.

You will need one accumulator variable for each character category.