请问关于getchar(),这两种用法,为什么有不同的结果
# include <stdio.h>int main()
{
char c;
int l = 0,s = 0,d = 0,o = 0;
c = getchar();
while (c != '\n')
{
if(c >= 'a' && c <='z' || c >='A'&& c <= 'Z')
l++;
else if(c == ' ')
s++;
else if(c>='0' && c <= '9')
d++;
else
o++;
}
printf("c = %d\n",c);
printf("l = %d,s = %d,d = %d,o = %d\n",l,s,d,o);
return 0;
}
和
# include <stdio.h>
int main()
{
char c;
int l = 0,s = 0,d = 0,o = 0;
while ((c = getchar())!= '\n')
{
if(c >= 'a' && c <='z' || c >='A'&& c <= 'Z')
l++;
else if(c == ' ')
s++;
else if(c>='0' && c <= '9')
d++;
else
o++;
}
printf("c = %d\n",c);
printf("l = %d,s = %d,d = %d,o = %d\n",l,s,d,o);
return 0;
}
这两个流程一看是一样的,为什么运行结果不一样??
[此贴子已经被作者于2016-3-22 16:08编辑过]