这个问题是这样的:scanf函数读取键盘缓冲区里的字符流,如果遇到空格,回车时就会截断字符流,把空格或者回车前的部分读到参数指定的地址(本例中是a)。假如你运行程序时,输入y以外的字符然后回车(注意这时键盘缓冲区里边有两个字符:'a','\n'),它就会先把这个字符付给a,会输出Input data error,please input again. 然后你重新开始loop,输出Please input the number: 然后它会把回车'\n'读到a里面,这时也是输出Input data error,please input again.这时候键盘缓冲区空了,就在输出Please input the number:并且等待键盘输入
代码改一下就可以了。如下:char a;loop:printf("Please input the number:");scanf("%c",&a);fflush(stdin);if(a!='y') {
printf("Input data error,please input again.\n");
goto l