C语言判断字符串类型及个数并输出,这里判断的是:
小写字母;大写字母;空格;数字;
#include <stdio.h>
int main()
{
char a;
int letter = 0, majuscule = 0, num = 0, space = 0, other = 0 ;
printf("请输入字符串:\n");
while ((a = getchar()) != '\n')
{
if (a >= 'a' && a <= 'z')
letter++;
else if (a >= 'A' && a <= 'Z')
majuscule++;
else if (a >= '0' && a <= '9')
num++;
else if (a == ' ')
space++;
else
other++;
}
printf("小写字母 :%d\n大写字母 : %d\n空格 : %d\n数字 : %d\n其他 : %d\n",letter,majuscule, space, num, other);
return 0;
}