一个求一行字符串中字母,空格等个数的程序,为什么空格的个数不对啊?
#include <stdio.h>void main()
{
int upper=0,lower=0,digit=0,space=0,other=0,i=0;
char *p,str[20];
printf("input a string:\n")
gets(str);
for(p=str;*p!='\0';p++)
{
if(*p>='A'&&*p<='Z')upper++;
else if(*p>='a'&&*p<='z')lower++;
else if(*p>='0'&&*p<='9')digit++;
else if(*p==' ')space++;
else other++;
}
printf("upper case:%d\nlower case:%d\ndigit:%d\nspace:\nother:%d\n",upper,lower,digit,space,other);
}