能问下为什么一定要加这一行处理非整数输入的代码呢?不加的话为什么输入其他整数程序会自动清理多余的数,而输入字符却不能呢?
int getnights(void)
{
int nights;
printf("Please enter the days you want live: \n");
while (scanf("%d",&nights) != 1)
{
scanf("%*s"); //处理非整数输入
printf("Please enter an integer,sun as 2.\n");
}
return nights;
}