-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileop.c
61 lines (51 loc) · 933 Bytes
/
fileop.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
#include "fileop.h"
#include <stdio.h>
#include <stdlib.h>
void CreateFile()
{
printf("creat Done\n");
}
void OpenFile()
{
printf("open Done\n");
}
void SaveFile()
{
printf("save Done\n");
}
void Exit()
{
printf("exit Done\n");
exit(0);
}
static CmdEntry cmdArray[10] = {
{&CreateFile, "create file"},
{&OpenFile, "open file"},
{&SaveFile, "save file"},
{&Exit, "exit"},
// <?? 1>?????????
{0, 0} // ??
};
void showHelp()
{
for (int i = 0; (i < 10) && cmdArray[i].pfuncmd; i++){
printf("%d\t%s\n", i, cmdArray[i].cHelp);
}
}
int main(void)
{
int iCmdNum;
char cTmp1[256];
while (1){
showHelp();
printf("Select item \n");
iCmdNum = getchar() - '0';
gets(cTmp1); //
if (iCmdNum >= 0 && iCmdNum < 10 && cmdArray[iCmdNum].pfuncmd){
cmdArray[iCmdNum].pfuncmd();
}
else{
printf("Inlegal No,please re-select\n");
}
}
}