while ((status = scanf("%d", &code)) != 1 || (code < 1 || code>5))
{
if (status != 1)
scanf("%*s"); //处理非整数输入 ???????
printf("enter an integer from 1 to 5,please.\n");
}
return code;
这是个检测用户错误输入的程序。
书上说是处理非整数输入,网上找了半天也没找到%*s时干什么用的
书是c primer plus第六版,第9章,265页
int a,b;
char b[10];
scanf("%d%*s",&a,b);
输入为:
12 abc
那么12将会读取到变量a中,但是后面的abc将在读取之后抛弃,不赋予任何变量
你输入完了之后要按回车吧,%*s就是吸收回车这个垃圾字符的