C语言:(用指针编写)输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?

#include <stdio.h>
#include <string.h>
int main()
{
char str[40],*p;
int a=0,b=0,c=0,d=0,e=0;
gets(str);
p=str;
while(*p!='\0')
{
if(*p++>='A'&&*p++<='Z')
a++;
if(*p++>='a'&&*p++<='z')
b++;
if(*p++>='0'&&*p++<='9')
c++;
if(*p++==' ')
d++;
else
e++;
}
printf("a=%5d\nb=%5d\nc=%5d\nd=%5d\ne=%5d\n",a,b,c,d,e);
return 0;
}
运行时不能得到正确结果,我想知道是什么原因

if(*p++>='A'&&*p++<='Z')
a++;
算法有问题,
你判断的时候,不管是否符合,都++运算了,而且可能还连加两次,那当前字符就不管它了么
温馨提示:答案为网友推荐,仅供参考
相似回答