C Language --> statistics on the number of occurrences of each type in the input string
Problem description: compile a program to count the number, white space character, and the number of times all other characters appear in the input string. Code implementation:
# Include <stdio. h> # include <ctype. h> int main () {int other = 0; int space = 0; int a [10] = {0}; int I = 0; int ch = 0; while (ch = getchar ())! = EOF) {/* // isspace library function --- determines whether the input string ch is null. if yes, the if condition is true. */If (isspace (ch) {space ++;}/* // isdigit database function --- determines whether the input string ch is a number. if yes, the if condition is true. */Else if (isdigit (ch) {a [ch-'0'] ++;} else {other ++ ;}} printf ("space = % d \ n", space); for (I = 0; I <10; I ++) {printf ("% d: % d \ n ", I, a [I]);} printf (" other = % d \ n ", other );}
The result is: