------------------------------------------------------ #include /* array1.c - count digits, whitespace, and others */ main() { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for (i = 0; i < 10; ++i) ndigit[i] = 0; while ((c = getchar()) != EOF) if (c >= '0' && c <= '9') ++ndigit[c-'0']; else if (c == ' ' || c == '\n' || 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); } $ gcc array1.c $ ./a.out < array1.c digits = 9 4 0 0 0 0 0 0 0 1, white space = 204, other = 356 $ --------------------------------------------------------- 1. "int ndigit[10]" reserves 10 integers, ndigit[0] through ndigit[9] 2. chars are just small integers, '0' equals 48 and '9' equals 57 in ascii, so [c-'0'] becomes 0 thorugh 9. 3. if (condition1) statement1 else if (condition2) statement2 else if (condition3) statement3 else statement4 4. No brackets {} for while because it contains a single "statement". ---------------------------------------------------------