统计字符串中的字母,数字,空格和其它字符.

#include<stdio.h>
#include<ctype.h>
int main()
{
    int i=0;
    char str[]="abc 123 %&def";
    int other=0,blank=0,alpha=0,digital=0;
    while(str[i])
    {
        if(isalpha(str[i])) //判断是否是字母
        {
            alpha++;
        }
        else if(isblank(str[i]))//判断是否是空格
        {
            blank++;
        }
        else if(isdigit(str[i]))//判断是否是数字
        {
            digital++;
        }
        else
            other++;      //其它字符
            i++;
    }
    printf("字母是%d个 ",alpha);
    printf("数字是%d个 ",digital);
    printf("空格是%d个 ",blank);
    printf("其他是%d个 ",other);
    return 0;
}



原文地址:https://www.cnblogs.com/wuzhang/p/wuzhang6.html