-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu3.c
101 lines (90 loc) · 2.76 KB
/
menu3.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**************************************************************************************************/
/* Copyright (C) mc2lab.com, SSE@USET, 2014-2015 */
/* */
/* FILE NAME : menu.c */
/* PRINCIPAL AUTHOR : HuangZhiheng */
/* SUBSYSTEM NAME : menu */
/* MODULE NAME : menu */
/* LANGUAGE : C */
/* TARGET ENVIRONMENT : ANY */
/* DATE OF FIST RELEASE : 2014/09/08 */
/* DESCRIPTION : This is a menu program */
/**************************************************************************************************/
/*
*Revision log:
*This is the 3th revision.
*Created by HuangZhiheng, 2014/09/08
*
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define DESC_LEN 1024
#define CMD_NUM 10
typedef struct DataNode
{
char cmd[DESC_LEN];
char desc[DESC_LEN];
struct DataNode *next;
}tDataNode;
tDataNode *CreateData(tDataNode *head)
{
head = NULL;
tDataNode *p = NULL;
int i;
char cmd[] = "0";
for(i=0; i<CMD_NUM; i++)
{
int n;
p = (tDataNode*)malloc(sizeof(tDataNode));
sprintf(p->desc, "This is %s cmd", cmd);
sprintf(p->cmd, "%s", cmd);
n = atoi(cmd);
if(n<9)
{
n++;
}
sprintf(cmd, "%d", n);
p->next = head;
head = p;
}
return head;
}
void ExeData(tDataNode *head)
{
tDataNode *p = head;
while(p != NULL)
{
printf("%s - %s\n", p->cmd, p->desc);
p = p->next;
}
while(1)
{
int cmd2;
printf("Input a CMD number\n");
scanf("%d", &cmd2);
if(cmd2<0||cmd2>9)
{
printf("This is a wrong cmd number\n");
printf("cmd2 is :%d\n",cmd2);
continue;
}
char cmd1[DESC_LEN];
sprintf(cmd1, "%d", cmd2);
p = head;
while(p != NULL)
{
if(strcmp(cmd1,p->cmd) == 0)
{
printf("%s - %s\n", p->cmd, p->desc);
break;
}
p = p->next;
}
}
}
main()
{
tDataNode *head = NULL;
ExeData(CreateData(head));
}