#include
#include
using namespace std;
/*
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
*/
void
count() {
//统计个数.
int letters = ;
int spaces = ;
int digit = ;
int others = ;
char curChar;
//注意的是,对(一行中)逐个字符进行读取时,'\n'对应ASCII值为10,而不是0,所以需要跟'\n'判断(不同于逐句判断).
while((curChar = getchar()) != '\n') {
if(isalpha(curChar)) //检查参数curChar是否为英文字母,在标准c中相当于使用“isupper(curChar)||islower(curChar)”
++letters;
else if(isdigit(curChar)) //检查参数curChar是否为阿拉伯数字0到9.
++digit;
else if(isspace(curChar))
++spaces;
else ++others;
}
printf("letters:%d, digits:%d, spaces:%d,others:%d\n", letters, digit, spaces, others);
//cout<
}