-
Notifications
You must be signed in to change notification settings - Fork 0
/
会员个人信息界面.cpp
159 lines (147 loc) · 2.95 KB
/
会员个人信息界面.cpp
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "会员head.h"
void MemMenu(char name[])
{
int choice = 0;
while (true) {
system("cls");
printf("1.余额查询\n");
printf("2.余额充值\n");
printf("0.退出\n");
scanf_s("%d", &choice);
if (choice < 0 || choice>2)break;
ShowMemMenu(choice, name);
}
}
void ShowMemMenu(int choice, char name[]) {
switch (choice)
{
case 0:
exit(0);
case 1: //余额查询
CheckMemMoney(name);
break;
case 2: //余额充值
RechargeMoney(name);
break;
default:
break;
}
}
void CheckMemMoney(char name[])
{
FILE* fp;
Mem* p, * q, * head = NULL, * ptr;
if ((fp = fopen("zhanghao.txt", "r")) == 0) {
printf("\n无法查询到该账号");
return;
}
rewind(fp);
p = (Mem*)malloc(sizeof(Mem));
//memset(p, 0x00, sizeof(Mem));
head = q = p;
while (!feof(fp)) {
if (fread(p, sizeof(Mem), 1, fp) != 1) {
break;
}
p->next = (Mem*)malloc(sizeof(Mem));
//memset(p->next, 0x00, sizeof(Mem));
q = p; //q是真正的尾节点
p = p->next; //p向后移动一个节点
}
q->next = NULL;
fclose(fp);
ptr = head;
while (ptr != NULL) {
if (strcmp(ptr->id, name) == 0) {
printf("您的余额为: %2lf", ptr->money);
break;
}
ptr = ptr->next;
}
/*Mem* head, * p = NULL;
int flag = 0;
p = head = read_Count();
while (p != NULL)
{
if (strcmp(name, p->id) == 0)
{
printf("您的余额为: %2lf", p->money);
flag = 1;
break;
}
else
{
printf("查询失败!");
getchar();
}
p = p->next;
}*/
}
void RechargeMoney(char name[])
{
//Mem* head = NULL, * p = NULL;
int i = 0, flag = 0;
double money;
char keyword[30];
printf("请输入您的密码:");
while (true) {
//fflush(stdin);
keyword[i] = getch();
if (keyword[i] == '\x0d') { //遇到回车符退出循环
keyword[i] = '\0';
break;
}
printf("* "); //保护用户隐私
i++;
}
FILE* fp;
Mem* p, * q, * head = NULL, * ptr;
if ((fp = fopen("zhanghao.txt", "r")) == 0) {
printf("\n无法查询到该账号");
return;
}
rewind(fp);
p = (Mem*)malloc(sizeof(Mem));
//memset(p, 0x00, sizeof(Mem));
head = q = p;
while (!feof(fp)) {
if (fread(p, sizeof(Mem), 1, fp) != 1) {
break;
}
p->next = (Mem*)malloc(sizeof(Mem));
//memset(p->next, 0x00, sizeof(Mem));
q = p; //q是真正的尾节点
p = p->next; //p向后移动一个节点
}
q->next = NULL;
fclose(fp);
ptr = head;
while (ptr != NULL) {
if (strcmp(ptr->id, name) == 0 && strcmp(keyword, p->key) == 0) {
printf("请输入您要充值的金额: ");
scanf_s("%lf", &money);
ptr->money += money;
break;
}
ptr = ptr->next;
}
SaveMem(head);
/*head = read_Count();
p = read_Count();
while (p != NULL)
{
if (strcmp(name, p->id) == 0 && strcmp(keyword, p->key))
{
printf("请输入您要充值的金额: ");
scanf_s("%lf", &money);
p->money += money;
flag = 1;
break;
}*/
/*else
{
printf("充值失败!");
getchar();
}*/
/*p = p->next;*/
}