#include<stdio.h>
int main(){
char ch;
int letter=0,blank=0,digit=0,other=0;
for(int i = 1;i<=10;i++){
ch = getchar();
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
letter ++;
else if(ch>='0'&&ch<='9')
digit ++;
else if(ch==' '||ch=='\n')
blank ++;
else
other++;
}
printf("letter = %d, blank = %d, digit = %d, other = %d",letter,blank,digit,other);
return 0;
}
知识点: char类型(实际存储的是字符的ascii码)
可以使用getchar()函数,每次读取单个字符。