int c, i, nwhite=0, nother=0;
int ndigit[10];
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar()) != '\n') {
if (c >= '0' && c <= '9')
++ndigit[c - '0'];//采用int型变量的相减关系得到对应数组索引
else if (c == ' ' || c == '\t')
++nwhite;
else
++nother;
}
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n",
nwhite, nother);
if (getchar() == EOF) {
putchar(EOF);
}
return 0;