-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.c
More file actions
44 lines (43 loc) · 823 Bytes
/
menu.c
File metadata and controls
44 lines (43 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h>
#include<stdlib.h>
#include "linklist.h"
int help();
int quit();
#define CMD_MAX_LEN 128
#define DESC_LEN 1024
#define CMD_NUM 10
static tDataNode head[]=
{
{"help", "this is help cmd!",help,&head[1]},
{"version","menu program v1.0",NULL,&head[2]},
{"quit", "quit from menu",quit,NULL}
};
int main()
{
while(1)
{
char cmd[CMD_MAX_LEN];
printf("Please input a cmd number ->");
scanf("%s",cmd);
tDataNode *p = FindCmd(head, cmd);
if(p == NULL)
{
printf("This is a wrong cmd!\n");
continue;
}
printf("%s - %s\n", p->cmd, p->desc);
if(p->handler != NULL)
{
p->handler();
}
}
}
int help()
{
ShowAllCmd(head);
return 0;
}
int quit()
{
exit(0);
}