统计字符

#include<stdio.h>
#include<string.h>

void main()
{
    int upper=0,lower=0,digit=0,space=0,other=0,i=0;

    char str[5000];
    gets(str);
    for(i=0;str[i]!='\0';i++)
    {
        if(str[i]>='a'&&str[i]<='z')
            lower++;
        else if(str[i]>='A'&&str[i]<='Z')
            upper++;
        else if(str[i]>='0'&&str[i]<='9')
            digit++;
        else if(str[i]==' ')
            space++;
        else
            other++;
    }
    printf("lower=%d\n",lower);
    printf("upper=%d\n",upper);
    printf("digit=%d\n",digit);
    printf("space=%d\n",space);
    printf("other=%d\n",other);

}

你可能感兴趣的:(统计字符)