输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。(C语言)
#include<stdio.h>
int main(){
char ch;
int space=0,number=0,character=0,other=0;
ch=getchar(); //字符输入
while(ch!='\n'){ // '\n'是回车
if(ch==' '){ //字符ch为空' '
space++;
}
else if(ch>='0'&&ch<='9'){ //字符为数字0~9
number++;
}
else if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z'){ //字符为字母a~z,A~Z
character++;
}
else{
other++;
}
ch=getchar();
}
printf("%d %d %d %d",character,number,space,other);
return 0;
}