一行文字,最多有80个字符。要求统计该行文字中包含的英文大写字母、小写字母、 数字、空格及其他字符的个数。c语言
时间: 2024-06-13 20:08:46 浏览: 7
以下是C语言的代码实现,可以统计一行文字中包含的英文大写字母、小写字母、数字、空格及其他字符的个数:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[80];
int i, upper, lower, digit, space, other;
printf("请输入一行文字(最多80个字符):\n");
fgets(str, 80, stdin);
upper = lower = digit = space = other = 0;
for (i = 0; str[i] != '\0'; i++) {
if (isupper(str[i])) {
upper++;
} else if (islower(str[i])) {
lower++;
} else if (isdigit(str[i])) {
digit++;
} else if (isspace(str[i])) {
space++;
} else {
other++;
}
}
printf("大写字母个数:%d\n", upper);
printf("小写字母个数:%d\n", lower);
printf("数字个数:%d\n", digit);
printf("空格个数:%d\n", space);
printf("其他字符个数:%d\n", other);
return 0;
}
```