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