如何判断一个字符串中有几个字母,数字和其他字符。

请尽量用简单的C语言来回答。

img


#include <stdio.h>
#include <string.h>
int main()
{
    char str[256];
    gets(str);
    int i,num = 0,word = 0,whiteSpace = 0,others = 0;
    for(i = 0;i < strlen(str);i++){
        if(str[i] >= '0' && str[i] <= '9'){
            num ++;
        }else if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z'){
            word ++;
        }else if(str[i] == ' '){
            whiteSpace ++;
        }else{
            others ++;
        }
    }
    printf("字母有%d个 数字有%d个 空格有%d个 其他有%d个", word, num, whiteSpace, others);
    return 0;
}