#include <stdio.h>
void load_menu(void);
int main(void)
{
load_menu();
return 0;
}
void load_menu(void)
{
int choice;
int loopagain;
do
{
printf("Menu \n\n");
printf("Please enter your choice: \n");
printf("1. \n");
printf("2.\n");
printf("3.\n");
printf("4. Exit\n");
if (scanf("%d",&choice)==1)
{
switch(choice)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4: printf("Quitting program!\n");
break;
default: printf("Invalid choice! Please try again\n");
printf("\n");
break;
}
}
else
{
printf("Characters are invalid, please enter a number: \n ");
if (scanf("%d",&loopagain)==1)
load_menu();
}
}while((choice !=4));
}
为什么当我输入一个字符时这仍然给我一个无限循环?这是一个菜单(case 语句仍然需要填写),但我正在处理 if 语句输入的字符,但它似乎仍然不起作用。谢谢