1.分类统计字符个数。在main主函数中采用gets函数输入一行文字,在count函数中统计其中的大写字母、小写字母、空格、数字以及其他字符各有多少。

1.分类统计字符个数。在main主函数中采用gets函数输入一行文字,在count函数中统计其中的大写字母、小写字母、空格、数字以及其他字符各有多少。


#include<stdio.h>
#include<string.h>
 int main()
{
    void count(char *p);
    char str[100];
    gets(str);  
    count(str);
    return 0;
}
void count(char* p)
{
     int upper=0,lower=0,space=0,digit=0,other=0;
     while (*p != '\0')        //字符串的结束符号位"\0"
     {
         if (('A' <= *p) && (*p <= 'Z'))
             upper++;
         else if (('a' <= *p) && (*p <= 'z'))
             lower++;
         else if (*p ==' ')
             space++;
         else if (('0' <= *p) && (*p <= '9'))
             digit++;
         else
             other++;
         p++;
     }
    printf("大写字母有:%d\n个小写字母有:%d个\n﹐空格有:%d个\n数字有:%d\n其他有:%d",upper,lower,space,digit,other);
}