/*
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数,
以回车表示输入结束,最后在屏幕上显示统计结果。
*/
#include <stdio.h>
#include <string.h>
int main()
{
int en, blank, num, other;
en = blank = num = other = 0;
char ch[100];
printf("请输入一段字符:\n");
gets(ch);
for(int i = 0 ; i < strlen(ch) ; i++)
{
if((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z'))
{
en++;
}else if(ch[i] == ' ')
{
blank++;
}else if(ch[i] >= '0' && ch[i] <= '9')
{
num++;
}else
{
other++;
}
}
printf("英文字母有:%d 个\n空格有:%d 个\n数字有:%d 个\n其它字符有:%d 个\n"
,en,blank,num,other);
return 0;
}