|
|
@ -7,19 +7,19 @@
|
|
|
|
#define N 50
|
|
|
|
#define N 50
|
|
|
|
int k = 1, n = 0, m = 0;
|
|
|
|
int k = 1, n = 0, m = 0;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct student {
|
|
|
|
typedef struct Bank {
|
|
|
|
char no[13];//卡号
|
|
|
|
char no[13];//卡号
|
|
|
|
char name[10];//姓名
|
|
|
|
char name[10];//姓名
|
|
|
|
char sex[8];//性别
|
|
|
|
char sex[8];//性别
|
|
|
|
int balance;//余额
|
|
|
|
int balance;//余额
|
|
|
|
char passwd[20];
|
|
|
|
char passwd[20];
|
|
|
|
} student, stu[max];
|
|
|
|
} bank, ban[max];
|
|
|
|
void fileWrite(int n, stu s);
|
|
|
|
void fileWrite(int n, ban s);
|
|
|
|
void modify() {
|
|
|
|
void modify() {
|
|
|
|
int j = 0;
|
|
|
|
int j = 0;
|
|
|
|
FILE * fp;
|
|
|
|
FILE * fp;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
stu s;
|
|
|
|
ban s;
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
j++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -80,7 +80,7 @@ void insert() {
|
|
|
|
scanf("%d", &n);
|
|
|
|
scanf("%d", &n);
|
|
|
|
FILE * fp;
|
|
|
|
FILE * fp;
|
|
|
|
if ((fp = fopen("a.txt", "at")) == NULL) return;
|
|
|
|
if ((fp = fopen("a.txt", "at")) == NULL) return;
|
|
|
|
stu s;
|
|
|
|
ban s;
|
|
|
|
for (i = 0; i<n; i++) {
|
|
|
|
for (i = 0; i<n; i++) {
|
|
|
|
printf("\n请输入第%d个用户的卡号:", i + 1);
|
|
|
|
printf("\n请输入第%d个用户的卡号:", i + 1);
|
|
|
|
scanf("\n%s", &s[i].no);
|
|
|
|
scanf("\n%s", &s[i].no);
|
|
|
@ -91,17 +91,18 @@ void insert() {
|
|
|
|
printf("\n请输入第%d 个用户的密码:", i + 1);
|
|
|
|
printf("\n请输入第%d 个用户的密码:", i + 1);
|
|
|
|
scanf("%s", &s[i].passwd);
|
|
|
|
scanf("%s", &s[i].passwd);
|
|
|
|
//写入文件
|
|
|
|
//写入文件
|
|
|
|
|
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
|
|
fprintf(fp, "%s %s %s %s %d \n", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance = 0);
|
|
|
|
fprintf(fp, "%s %s %s %s %d \n", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance = 0);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("添加成功!!!\n");
|
|
|
|
printf("添加成功!!!\n");
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void del() {
|
|
|
|
void del() {
|
|
|
|
int j = 0;
|
|
|
|
int j = 0;
|
|
|
|
FILE * fp, *fp1;
|
|
|
|
FILE * fp, *fp1;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
stu s;
|
|
|
|
ban s;
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d ", &s[j].no, &s[j].name, &s[j].sex[j],&s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
j++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -138,7 +139,7 @@ void seek() {
|
|
|
|
int j = 0,flag=0;
|
|
|
|
int j = 0,flag=0;
|
|
|
|
FILE * fp;
|
|
|
|
FILE * fp;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
stu s;
|
|
|
|
ban s;
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
j++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,7 +149,7 @@ void seek() {
|
|
|
|
lable1:
|
|
|
|
lable1:
|
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
|
scanf("%s", &s1);
|
|
|
|
scanf("%s", &s1);
|
|
|
|
if(s1=0)
|
|
|
|
if (strcmp(s1, "0") == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -183,18 +184,19 @@ void save()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int j = 0,flag=0;
|
|
|
|
int j = 0,flag=0;
|
|
|
|
FILE * fp;
|
|
|
|
FILE * fp;
|
|
|
|
if ((fp = fopen("a.txt", "r")) == NULL) return;
|
|
|
|
if ((fp = fopen("a.txt", "r+")) == NULL) return;
|
|
|
|
stu s;
|
|
|
|
ban s;
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
while (fscanf(fp, "%s %s %s %s %d", &s[j].no, &s[j].name, &s[j].sex[j], &s[j].passwd, &s[j].balance) == 5) {
|
|
|
|
j++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n = j;
|
|
|
|
n = j;
|
|
|
|
int i = 0, item,save;
|
|
|
|
struct Bank *str = s;
|
|
|
|
|
|
|
|
int i = 0, item,save,aftersave;
|
|
|
|
char s1[13], s2[20];
|
|
|
|
char s1[13], s2[20];
|
|
|
|
lable1:
|
|
|
|
lable1:
|
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
|
printf("请输入卡号(输入0返回主菜单):\n");
|
|
|
|
scanf("%s", &s1);
|
|
|
|
scanf("%s", &s1);
|
|
|
|
if(s1=0)
|
|
|
|
if (strcmp(s1, "0") == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -205,9 +207,11 @@ int j = 0,flag=0;
|
|
|
|
if (strcmp(s[i].passwd, s2) == 0) {
|
|
|
|
if (strcmp(s[i].passwd, s2) == 0) {
|
|
|
|
printf("请输入您要存款的金额:");
|
|
|
|
printf("请输入您要存款的金额:");
|
|
|
|
scanf("%d",&save);
|
|
|
|
scanf("%d",&save);
|
|
|
|
fprintf(fp, "%s %s %s %s %d \n", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance = s[i].balance+save);
|
|
|
|
s[i].balance = save + s[i].balance;
|
|
|
|
printf("存款成功!")
|
|
|
|
fileWrite(n, s);
|
|
|
|
printf("当前余额为%d元",s[i].balance);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("存款成功!\n");
|
|
|
|
|
|
|
|
printf("当前余额为%d元\n",s[i].balance);
|
|
|
|
flag = 2;
|
|
|
|
flag = 2;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -221,11 +225,11 @@ int j = 0,flag=0;
|
|
|
|
printf("您输入的用户名不存在,请重新输入\n");
|
|
|
|
printf("您输入的用户名不存在,请重新输入\n");
|
|
|
|
goto lable1;
|
|
|
|
goto lable1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
system("pause");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void fileWrite(int n, stu s) {
|
|
|
|
void fileWrite(int n, ban s) {
|
|
|
|
FILE *fp1;
|
|
|
|
FILE *fp1;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
if ((fp1 = fopen("a.txt", "w")) == NULL) return;
|
|
|
|
if ((fp1 = fopen("a.txt", "w")) == NULL) return;
|
|
|
@ -233,7 +237,6 @@ int j = 0,flag=0;
|
|
|
|
fprintf(fp1, "%s %s %s %s %d ", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance);
|
|
|
|
fprintf(fp1, "%s %s %s %s %d ", s[i].no, s[i].name, s[i].sex,s[i].passwd, s[i].balance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp1);
|
|
|
|
fclose(fp1);
|
|
|
|
printf("保存成功!!!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 界面*/
|
|
|
|
/* 界面*/
|
|
|
|
void menu() {
|
|
|
|
void menu() {
|
|
|
@ -261,6 +264,7 @@ void menu() {
|
|
|
|
seek();
|
|
|
|
seek();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
save();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
break;
|