1 #include<stdio.h>
2 int main()
3 {
4 char ch;
5 int speace, num, other, letter;
6 speace = 0;
7 num = 0;
8 other = 0;
9 letter = 0;
10 while ((ch = getchar()) != '\n')//getchar函数可以把输入的数暂放缓存区并逐个调用执行
11 {
12 if ('a' <= ch&&ch <= 'z' || 'A' <= ch&&ch <= 'Z')//判断是否是字母
13 letter++;
14 else if (ch >= '0' && ch <= '9')//判断是否是数字
15 num++;
16 else if (ch == ' ')//判断是否是空格
17 speace++;
18 else //其他的字符
19 other++;
20 }
21
22 printf("字母%d\t数字%d\t空格%d\t其他%d", letter, num, speace, other);
23
24 return 0;
25 }