blob: 05660f012e563aa79b87bf697e8ef2a17608c3ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <stdio.h>
/* count digits, white space, and others */
int
main()
{
int c, i, nwhite, nother;
int ndigit[10] = {0};
int nchar[26] = {0};
nwhite = nother = 0;
while ((c = getchar()) != EOF) {
if (c >= '0' && c <= '9') {
++ndigit[c - '0'];
} else if (c == ' ' || c == '\t' || c == '\n') {
++nwhite;
} else if (c >= 'a' && c <= 'z') {
++nchar[c - 'a'];
} else {
++nother;
}
}
printf("digits =");
for (i = 0; i < 10; ++i) {
printf(" %d", ndigit[i]);
}
printf("\nchars =");
for (i = 0; i < 26; ++i) {
printf(" %d", nchar[i]);
}
printf("\nwhite space = %d\nother = %d\n", nwhite, nother);
return 0;
}
|