#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, upp, low, dig, spa, other;
char text[3][80];
upp = low = dig = spa = other = 0;
for (i = 0; i < 3; i++)
{
printf("please input line %d:\n", i + 1);
gets(text[i]);
for (j = 0; j < 80 && text[i][j] != '\0'; j++);
{
if (text[i][j] >= 'A' && text[i][j] <= 'Z')
upp++;
else if (text[i][j] >= 'a' && text[i][j] <= 'z')
low++;
else if (text[i][j] >= '0' && text[i][j] <= '9')
dig++;
else if (text[i][j] == ' ')
spa++;
else
other++;
}
}
printf("\nupper case:%d\n", upp);
printf("lower case :%d\n", low);
printf("digit :%d\n", dig);
printf("spa :%d\n", spa);
printf("other :%d\n", other);
return 0;
}
统计一个字符串中的大小写字母,数字,空格及其他字母
最新推荐文章于 2023-12-06 13:05:12 发布