编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。 #include <stdio.h> int main() { int ch= 0; intspace = 0; intother = 0; int i =0; intnum[10] = {0}; while((ch = getchar()) != EOF) { if(isspace(ch)) { space++; } elseif (ch >= ‘0‘&& ch <= ‘9‘) { num[ch - ‘0‘]++; } else { other++; } } for (i= 0; i < 10; i++) { printf("%d--->%d\n", i, num[i]); } printf("space= %d\n", space); printf("other= %d\n", other); system("pause"); return0; } 运行结果为:
原文:http://760470897.blog.51cto.com/10696844/1705269