-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.c
59 lines (54 loc) · 889 Bytes
/
menu.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#define DESC_LEN 50
#define CMD_NUM 10
typedef struct DataNode
{
int cmd;
char descpt[DESC_LEN];
struct DataNode* next;
} tDataNode;
int main()
{
tDataNode *head = NULL;
tDataNode *p = NULL;
int i;
/* Init Command List */
for(i=0; i<CMD_NUM; i++)
{
p = (tDataNode*)malloc(sizeof(tDataNode));
p->cmd = i;
snprintf(p->descpt, DESC_LEN, "This is Command %d.", i);
p->next = head;
head = p;
}
printf("Menu List:\n");
p = head;
while(p != NULL)
{
printf("%d--%s\n", p->cmd, p->descpt);
p = p->next;
}
/* Command Line begins */
while(1)
{
int cmd;
printf("Input a cmd number>");
scanf("%d", &cmd);
if(cmd >= CMD_NUM)
{
printf("This is a wrong commad!\n");
continue;
}
p = head;
while(p != NULL)
{
if(cmd == p->cmd)
{
printf("%s\n", p->descpt);
break;
}
p = p->next;
}
}
return 0;
}