|
|
|
|
|
|
|
Let's look at how this problem is simplified by the fact that the index itself has meaning (semantic content). |
|
|
|
|
|
|
|
|
Data Structures: An array of frequencies (freqCount) indexed by the characters being counted. |
|
|
|
|
|
|
|
|
Open dataFile (and verify success)
Zero out freqCount
Read inputChar from dataFile
WHILE NOT EOF on dataFile
IF inputChar is a printable character
Increment freqCount[inputChar] by 1
Read inputCharfrom dataFile
Print characters and frequencies |
|
|
|
|
|
|
|
|
|
Zero FreqCount (Out: freqCount) Level 1 |
|
|
|
|
|
|
|
|
|
FOR index going from MIN-CHAR through MAX-CHAR
Set freqCount[index] = 0 |
|
|
|
|
|
|
|
|
|
|
Is Printable (In: inputChar) |
|
|
|
|
|
|
|
|
|
Use the standard library function isprint |
|
|
|
|
|
|
|
|
|
|
Print Characters and Frequencies (In: freqCount) |
|
|
|
|
|
|
|
|
|
FOR index going from MIN-CHAR through MAX-CHAR
Print index, " occurred ", freqCount[index], " time(s)" |
|
|
|
|
|
|
|
|
|
|
The Is Printable module can be implemented as a call to the library function isprint (available through the header file ctype.h), so we code the function call directly in the main module. |
|
|
|
|
|