From 21cf0f25ae9a8068c7457d20d845ff4630b7af95 Mon Sep 17 00:00:00 2001 From: m59637281 <18408000220@stu.hut.edu.cn> Date: Thu, 10 Jan 2019 21:30:19 +0800 Subject: [PATCH] fffunctions --- account_struct.c => define_struct.c | 2 +- del_account.c | 33 +++++++++++++++++------- get_account.c | 2 +- insert_account.c | 39 +++++++++++++++++++++-------- list_account.c | 9 ++++++- search_account.c | 15 ++++++----- search_key.c | 7 ++++++ store_account.c | 7 ++++++ 8 files changed, 86 insertions(+), 28 deletions(-) rename account_struct.c => define_struct.c (75%) create mode 100644 search_key.c create mode 100644 store_account.c diff --git a/account_struct.c b/define_struct.c similarity index 75% rename from account_struct.c rename to define_struct.c index b6b934f..a289aa8 100644 --- a/account_struct.c +++ b/define_struct.c @@ -1,4 +1,4 @@ -typedef struct bankaccount//定义账户格式模块函数 +typedef struct bankaccount//定义账户格式 { int account; int key; diff --git a/del_account.c b/del_account.c index 774aa15..4a46a91 100644 --- a/del_account.c +++ b/del_account.c @@ -1,14 +1,29 @@ -void del_account(FILE *fp,int accountnum)//删除账号信息模块 +void del_account(FILE *fp,int accountnum) { - int i; - if(search_account(fp,accountnum)==0) - printf("无法找到此账户!\n"); + int i, key; + if(search_account(fp,accountnum,1)==0) + printf("无法找到此账户!\n"); else { - for(i = 0;i>账号:"); - scanf("%d",&(newaccount.account)); - printf(">>密码:"); + printf(">>您的账号为:"); + printf("%d\n", accountnum); + printf(">>请您输入密码:"); scanf("%d",&(newaccount.key)); - printf(">>姓名:"); - scanf("%s",newaccount.name); - printf(">>余额:"); - scanf("%f",&(newaccount.balance)); - fseek(fp,0L,SEEK_END); - fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance); + system("cls"); + printf("请您再次输入刚才的密码:\n"); + do{ + scanf("%d", &subkey); + getchar(); + if (subkey == newaccount.key) + break; + else + printf("两次的密码不一样!\n请再次输入第一次的密码或输入0退出注册\n"); + }while (subkey != 0); + if (subkey != 0) + { + printf("密码设置成功!\n 请您完善个人信息\n"); + printf(">>姓名:"); + scanf("%s",newaccount.name); + printf(">>请您输入初始余额:"); + scanf("%f",&(newaccount.balance)); + fseek(fp,0L,SEEK_END); + fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance); + printf("账户创建成功!\n"); + } + else + printf("创建失败!"); } diff --git a/list_account.c b/list_account.c index 4a43e49..9001d12 100644 --- a/list_account.c +++ b/list_account.c @@ -1,4 +1,4 @@ -void list_account(FILE *fp)//列出所有账号信息模块函数 +void list_account(FILE *fp) { int i =0; printf("合计%d个账号:\n",cur_account-1);// cur_account减去多加的1 @@ -10,3 +10,10 @@ void list_account(FILE *fp)// printf("余额:%.2f\n",accountcollection[i].balance); } } +int search_key(FILE *fp,int key,int i) +{ + if (accountcollection[i].key == key) + return 1; + else + return 0; +} diff --git a/search_account.c b/search_account.c index 185596f..77fa8f8 100644 --- a/search_account.c +++ b/search_account.c @@ -1,16 +1,19 @@ -int search_account(FILE *fp,int accountnum)//管理员调用模块函数 +int search_account(FILE *fp,int accountnum,int flag) { int i =0; for(i = 0;i< cur_account-1;i++) { if(accountcollection[i].account == accountnum) { - printf("账户:%d:\n",i+1); - printf("账号:%d\n",accountcollection[i].account); - printf("姓名:%s\n",accountcollection[i].name); - printf("余额:%.2f\n",accountcollection[i].balance); + if(flag == 1) + { + printf("账户:%d:\n",i+1); + printf("账号:%d\n",accountcollection[i].account); + printf("姓名:%s\n",accountcollection[i].name); + printf("余额:%.2f\n",accountcollection[i].balance); + } - return 1; + return i + 1; } } return 0; diff --git a/search_key.c b/search_key.c new file mode 100644 index 0000000..2a489e2 --- /dev/null +++ b/search_key.c @@ -0,0 +1,7 @@ +int search_key(FILE *fp,int key,int i) +{ + if (accountcollection[i].key == key) + return 1; + else + return 0; +} diff --git a/store_account.c b/store_account.c new file mode 100644 index 0000000..2868153 --- /dev/null +++ b/store_account.c @@ -0,0 +1,7 @@ +void store_account(FILE*fp) +{ + int i = 0; + for(i = 0;i