编写一函数void fun(char srt[]),统计并输出字符串中字母,数字空格和其他字符的个

编写一函数void fun(char srt[]),统计并输出字符串中字母,数字空格和其他字符的个数,在主函数中任意输入一个字符串,并调用fun函数,各位大神拜托了,考试中

#include <stdio.h>

void fun(char str[]);

int main(void)
{
fun("123 abcd !@$%^");

return 0;
}
void fun(char str[])
{
int nChar = 0;
int nNum = 0;
int nOther= 0;
int nSpace= 0;

printf("%s \n", str);

while (*str != '\0')
{
if (*str>='0' && *str<='9')
{
nNum++;
}
else if ((*str>='a' && *str<='z') || (*str>='A' && *str<='Z'))
{
nChar++;
}
else if (*str == ' ')
{
nSpace++;
}
else
{
nOther++;
}

str++;
}

printf("字母数为:%d \n", nChar);
printf("数字数为:%d \n", nNum);
printf("空格数为:%d \n", nSpace);
printf("其它为 :%d \n", nOther);
}
温馨提示:答案为网友推荐,仅供参考