scanf语句
#include <stdio.h>main()
{
int n;
do
{
printf("please input a odd number.\n");
scanf("%d",&n);
}while((n>15)||(n<3)||(n%2==0));
getch();
}
以上程序,当我输入非数字的字符时,结果是执行无限循环的printf("please input a odd number.\n");根本不再做scanf的动作,为什么?
[此贴子已经被作者于2006-2-22 10:00:46编辑过]
----------------解决方案--------------------------------------------------------
I found the answer myself.
reason:
The next character read can't be converted under the current format (for example, an A when the format is decimal).
----------------解决方案--------------------------------------------------------
good job
----------------解决方案--------------------------------------------------------
well done
----------------解决方案--------------------------------------------------------
楼主你的程序好像没有结束语句,只有条件。
----------------解决方案--------------------------------------------------------
#include <stdio.h>
int main()
{
int n;
do
{
printf("please input a odd number.\n");
}while((scanf("%d",&n)==1)&&((n>15)||(n<3)||(n%2==0)));
getch();
return 0;
}
按照自己的要求再完善一下吧
[此贴子已经被作者于2006-3-4 17:31:54编辑过]
----------------解决方案--------------------------------------------------------
我个人认为是你类型选用的错误
你用数组做做,当输入字符也许不会有错
int占用字节和char是不一样的
----------------解决方案--------------------------------------------------------
楼上的话差矣,不知道是何意思
----------------解决方案--------------------------------------------------------
楼上你的程序同样是死循环,
----------------解决方案--------------------------------------------------------
不是死循环啊!!!????
----------------解决方案--------------------------------------------------------