输入一行文字,统计并输出期中大写字母、小写字母、空格、数字及其他字符各有多少,要求用指针方程编程实现。
时间: 2023-07-10 16:04:52 浏览: 41
```c
#include <stdio.h>
#include <ctype.h>
void count(char *str, int *upper, int *lower, int *space, int *digit, int *other) {
while (*str != '\0') {
if (isupper(*str)) {
(*upper)++;
} else if (islower(*str)) {
(*lower)++;
} else if (*str == ' ') {
(*space)++;
} else if (isdigit(*str)) {
(*digit)++;
} else {
(*other)++;
}
str++;
}
}
int main() {
char str[100];
int upper = 0, lower = 0, space = 0, digit = 0, other = 0;
printf("请输入一行字符串:\n");
fgets(str, 100, stdin);
count(str, &upper, &lower, &space, &digit, &other);
printf("大写字母:%d\n", upper);
printf("小写字母:%d\n", lower);
printf("空格:%d\n", space);
printf("数字:%d\n", digit);
printf("其他字符:%d\n", other);
return 0;
}
```