Linux 终端编程:菜单程序与终端控制详解
1. 用 C 语言重写菜单程序
我们尝试用 C 语言重写菜单程序,将其命名为 menu1.c 。以下是具体步骤:
1. 定义菜单数组和 getchoice 函数原型
#include <stdio.h>
char *menu[] = {
"a - add new record",
"d - delete record",
"q - quit",
NULL,
};
int getchoice(char *greet, char *choices[]);
- 主函数调用
getchoice
int main()
{
int choice = 0;
do
{
choice = getchoice("Please select an action", menu);
printf("You have chosen: %c\n", choice);
} while(choice != 'q');
exit(0);
}
-
getchoice函数实现
超级会员免费看
订阅专栏 解锁全文
33万+

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



