从键盘输入一个字符串,利用指针统计该字符串中大写字符,小写字符,空格,数字及其他字符的个数。
#include<stdio.h>
int main() {
int upp = 0, low = 0, space = 0, digit = 0, other = 0;
char str[100] = {0};
char* p = str;
printf("请输入一行字符串:");
gets(str);
p = &str[0];
while (*p != '\0') {
if ((*p >= 'A') && (*p <= 'Z'))
upp++;
else if ((*p >= 'a') && (*p <= 'z'))
low++;
else if ((*p >= '0') && (*p <= '9'))
digit++;
else if (*p == ' ')
space++;
else
other++;
p++;
}
printf("该字符串中的大写字母数为:%d\n", upp);
printf("该字符串中的小写字母数为:%d\n",low);
printf("该字符串中的数字数为:%d\n", digit);
printf("该字符串中的空格数为:%d\n",space);
printf("该字符串中的其他字符数为:%d\n", other);
return 0;
}


这篇文章详细描述了一个C语言程序,通过指针遍历用户输入的字符串,分别计算其中大写字符、小写字符、数字、空格和其他字符的数量。
8230

被折叠的 条评论
为什么被折叠?



