-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
122 lines (108 loc) · 2.72 KB
/
main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "func.h"
int version[3]={0, 5, 0};
char versionInfo[8]="alpha";
// Information
void start()
{
printf("\n\n会员卡管理程序\n版本 %s %d.%d.%d\n", versionInfo, version[0], version[1], version[2]);
}
void getOp()
{
while(1) {
printf("\n请输入需要的操作代号并按Enter(回车键):");
int valid=1;
if ((valid=scanf("%d", &op))==0) {
printf("您的输入不正确,请重新输入:");
continue;
} else {
return;
}
}
}
// Menu
void menu3() {
printf("1. 按姓名查找\n2. 按卡号查找\n3. 用户遍历\n");
getOp();
switch (op) {
case 1: {
searchWithName();
break;
}
case 2: {
searchWithNum();
break;
}
case 3: {
userTraversal();
break;
}
}
}
void menu(char *userFilePath, char *ieFilePath) {
printf("1. 用户消费\n2. 用户充值\n3. 查找用户\n4. 新增用户\n5. 修改用户资料\n6. 删除用户\n7. 导出用户资料\n8. 导入用户资料\n0. 退出程序\n");
getOp();
switch(op) {
case 0:
fwrite(user, sizeof(struct userInfo), MAX_USER, userFile);
rewind(userFile);
fclose(userFile);
free(userFilePath);
free(ieFilePath);
ieFilePath=NULL;
userFilePath=NULL;
exit(1);
break;
case 1:
consume();
break;
case 2:
charge();
break;
case 3:
menu3();
break;
case 4:
addUser();
break;
case 5:
editUser();
break;
case 6:
deleteUser();
break;
case 7:
exportFile(ieFilePath);
break;
case 8:
importFile(ieFilePath);
break;
default:
printf("未知操作,请重试:\n\n");
sleep(1);
}
}
// Main
int main(int argc, char *argv[])
{
start();
char *path=argv[0];
char *truncate;
truncate=strrchr(path, 'm');
*truncate='\0';
char *userFilePath=malloc(sizeof(char)*(strlen(path)+16));
char *ieFilePath=malloc(sizeof(char)*(strlen(path)+16)); // ie means import and export.
strcpy(userFilePath, path);
strcpy(ieFilePath, path);
strcat(userFilePath, "userFile");
strcat(ieFilePath, "exportFile.txt");
printf("当前用户资料存放目录:%s\n", path);
checkUserFile(userFilePath);
while (1) {
menu(userFilePath, ieFilePath);
}
return 0;
}