求教,该程序,在输入字符里逗号后面为空格,输出结果中计算其他字符数时出错
问题:在输入字符里逗号后面为空格,输出结果中计算其他字符数时出错例:输入1,'空格'a
输出结果其他字符为:2
空格在‘,’前面时,计算正确!
请教:为什么计算其他字符时出错
谢谢
代码如下:
程序代码:#include<stdio.h>
int main()
{
char c;
int Letter = 0, Space = 0, Number = 0, Other = 0;
while ((c=getchar())!='\n')
{
if (c>='A'&&c<='Z'||c>='a'&&c<='z')
{
Letter++;
}
else if (c==' ')
{
Space++;
}
else if (c>='0'&&c<='9')
{
Number++;
}
else
{
Other++;
}
}
printf("In this string, there are:\nLetter:%d\nSpace:%d\nNummber:%d\nOther:%d\n", Letter, Space, Number, Other);
return 0;
}[此贴子已经被作者于2017-6-16 01:04编辑过]









