#include <stdio.h> int main() { int letter=0,space=0,digit=0,others=0; //声明英文字母,空格,数字和其他字符的计数变量初始化为0 char c; //声明接收字符串的变量 while((c=getchar())!='\n'){ // 以回车符为结束的判断标记 if(c==' ') // 检测到空格 space++; else if(c>='0'&&c<='9') // 检测到数字 digit++; else if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) // 检测到字母,要同时考虑字母的大小写 letter++; else others++; } //输出结果 printf("The number of letters is:%d\n",letter); printf("The number of spaces is:%d\n",space); printf("The number of digits is:%d\n",digit); printf("The number of other words is:%d\n",others); return 0; }