代码如下:#define _CRT_SECURE_NO_WARNINGS 1
#include <ctype.h>
#include<stdio.h>
int main() {
char ch ;
int upper_count =0, word=0, lower_count =0,number=0;
while ((ch = getchar()) != EOF) {
if (isdigit(ch) != 0) {
number++;
}
else if (islower(ch) != 0) {
lower_count++;
}
else if (isupper(ch) != 0) {
upper_count++;
}
else if (isspace(ch) != 0) {
word++;
}
}
printf("数字字符数%d\n", number);
printf("小写字母数%d\n", lower_count);
printf("大写字母数%d\n", upper_count);
printf("单词数%d\n", word);
return 0;
}
这个是EOF的结束条件注意一下
Ctrl+D键(在Linux和Mac上)或Ctrl+Z键(在Windows上)