使用ctype.h中的character test function对键盘输入的一行字符串(≤80 char)进行类型判断,并在输入结束后打印统计结果。
输入一行字符为:姓名的拼音 学号 特殊字符(自选)。按常规写法用空格分开
#include<stdio.h>
#include<ctype.h>
int main()
{
int i;
int litter,space,num,others;
litter = space = num = others = 0;
char ch[81];
fgets(ch,81,stdin);
for(i=0;i<=80;i++)
{
if(isalpha(ch[i]))
litter++;
else if(ch[i] == ' ')
space++;
else if(isdigit(ch[i]))
num++;
else
others++;
if(ch[i]=='\0')
break;
}
printf("There are %d litters,%d spaces,%d nums,%d others",litter,space,num,others-2);
return 0;
}