求字符串中各类字符的个数,感觉做对了,但运行出错,错在哪儿
#include <stdio.h>void main()
{
void len(char *p);
char ch[100];
printf("请输入一段含大小写字母、空格等字符:\n");
gets(ch);
len(ch);
}
void len(char *p)
{
int i=0,k=0,j=0,t=0,m=0,n=0;
while(p[i]!='\0')
{
if(p[i]>='A'&&p[i]<='Z')
k++;
else if(p[i]>='a'&&p[i]<='z')
j++;
else if(p[i]>=' ')
t++;
else if(p[i]>='1'&&p[i]<='9')
m++;
else
{
n++;
i++;
}
}
printf("大写字母的个数为:%3d个\n",k);
printf("小写字母的个数为:%3d个\n",j);
printf("空格的个数为:%3d个\n",t);
printf("数字的个数为:%3d个\n",m);
printf("其它字符的个数为:%3d个\n",n);
}