//8.8 输入一行文字,找出其中大写字母、小写字母、空格、数字以及其他字符各有多少。
#include <stdio.h>
int main()
{
int uper = 0, lower = 0, digit = 0, space = 0, other = 0, i = 0;
char s[40], *p;
printf("input string:\n");
while ((s[i] = getchar()) != '\n') i++;
p = s;
while (*p != '\n') //注意此处不是‘\0’\0为字符串输入使用的结尾。
{
if ((*p >= 'A') && (*p <= 'Z'))
uper=uper+1;
else if ((*p >= 'a') && (*p <= 'z'))
lower=lower+1;
else if ((*p >= '0') && (*p <= '9'))
digit=digit+1;
else if (*p == ' ')
space=space+1;
else
other=other+1;
p=p+1;
}
printf(" uper=%d\n lower=%d\n digit=%d\n space=%d\n other=%d\n", uper, lower, digit, space, other);
return 0;
}
8.8 输入一行文字,找出其中大写字母、小写字母、空格、数字以及其他字符各有多少。
最新推荐文章于 2023-07-29 13:56:18 发布