编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数。

各位高手,有劳了!

#include<stdio.h>
#include<string.h>
void count(char *p)
{
int ch=0,num=0,space=0,other=0;
int i;
for(i=0;i<strlen(p);i++)
if(p[i]>='A' && p[i]<='z')
ch++;
else if(p[i]>='0' && p[i]<='9')
num++;
else if(p[i]==' ')
space++;
else other++;
printf("字母:%10d\n数字:%10d\n空格:%10d\n其它字符:%6d\n",ch,num,space,other);
}
void main()
{
char str[100];
printf("请输入一个字符串:");
gets(str);
count(str);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-21
fivestar502 兄弟写的正解!