|
|
|
|
|
|
|
occurred 10 time(s)
+ occurred 2 time(s)
, occurred 2 time(s)
. occurred 2 time(s)
C occurred 1 time(s)
I occurred 2 time(s)
R occurred 1 time(s)
a occurred 5 time(s)
b occurred 1 time(s)
c occurred 2 time(s)
d occurred 1 time(s)
e occurred 7 time(s)
f occurred 1 time(s)
i occurred 1 time(s)
l occurred 3 time(s)
n occurred 3 time(s)
o occurred 4 time(s)
r occurred 4 time(s)
s occurred 4 time(s)
t occurred 1 time(s)
u occurred 2 time(s)
v occurred 1 time(s)
y occurred 1 time(s) |
|
|
|
|
|
|
|
|
Testing: In order to test this program, we must verify that it counts characters correctly. To do so, we create a data file that contains all the printable characters at least once and some of them more than once. |
|
|
|
|
|
|
|
|
We add a word of caution about the choice of looping structure to use when processing arrays. The most common error in processing arrays is an out-of-bounds array index. That is, the program attempts to access a component using an index that is either less than zero or greater than the array size minus one. For example, given the declarations |
|
|
|
|
|
|
|
|
char line[100];
int counter; |
|
|
|
|
|
|
|
|
the following For statement would print the 100 elements of the line array and then print a 101st value-the value that resides in memory immediately beyond the end of the array. |
|
|
|
|
|