输入一行文字,找出其中大写字母、小写字母、空格、数字以及其他字符各有多少。
#include <stdio.h>
void countCharacters(char *str, int *upper, int *lower, int *space, int *digit, int *other) {
*upper = *lower = *space = *digit = *other = 0;
while (*str != '\0') {
if (*str >= 'A' && *str <= 'Z') {
(*upper)++;
} else if (*str >= 'a' && *str <= 'z') {
(*lower)++;
} else if (*str == ' ') {
(*space)++;
} else if (*str >= '0' && *str <= '9') {
(*digit)++;
} else {
(*other)++;
}
str++;
}
}
int main() {
char str[200];
int upper, lower, space, digit, other;
printf("Enter a line of text: ");
f