//输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
#include <stdio.h>
int main()
{
int letter,space,num,other;
char c;
c = getchar();
while(c != '\n')
{
if(c >= 'a'&&c <= 'z'||c >= 'A'&&c <= 'Z')
letter++;
else if(c == ' ')
space++;
else if(c >= '0'&&c <= '9')
num++;
else
other++;
c = getchar();
}
printf("英文字母有%d个,空格有%d个,数字有%d个,其他字符有%d个",letter,space,num,other);
}
谭浩强C程序设计(第四版)p140第4题
复习:
1.getchar()与while结合使用