代码:
···
void show_menu()
{int menu_num;
system("clear");
printf("welcome to student system!\n");
printf("please select the number you want!\n");//chose the function.
printf("1.registe\n");
printf("2.login\n");
printf("I chose:");
scanf("%d",&menu_num);
getchar();
if(menu_num != 1 && menu_num != 2 )
{
printf("chose error,please input again:\n");
show_menu();
}
···
问题:
调用show_menu();函数后,system("clear"),无法打印语句: printf("chose error,please input again:\n");
解决方法:
if(menu_num != 1 && menu_num != 2 )
{
getchar();
printf("chose error,please input again:\n");
getchar();
show_menu();
}
本文介绍了一个简单的C语言程序,该程序包含一个显示菜单并处理用户输入的函数。文章详细解释了如何修正当用户输入无效选项时导致的程序卡死问题,并提供了一种有效的解决方案。
2万+

被折叠的 条评论
为什么被折叠?



