diff --git a/account_struct.c b/account_struct.c new file mode 100644 index 0000000..b6b934f --- /dev/null +++ b/account_struct.c @@ -0,0 +1,9 @@ +typedef struct bankaccount//定义账户格式模块函数 +{ + int account; + int key; + char name[32]; + float balance; +}BANKACCOUNT; +BANKACCOUNT accountcollection[MAXACCOUNT]; +int cur_account = 0; diff --git a/del_account.c b/del_account.c new file mode 100644 index 0000000..774aa15 --- /dev/null +++ b/del_account.c @@ -0,0 +1,14 @@ +void del_account(FILE *fp,int accountnum)//删除账号信息模块 +{ + int i; + if(search_account(fp,accountnum)==0) + printf("无法找到此账户!\n"); + else + { + for(i = 0;i -#include -int main(void) -{ - int n; - char words[100][100][100]; - char word[100]; - char password[100]; - while (scanf("%d", &n) != EOF) - { - getchar(); - if (n == 1) - { - int i = 0; - gets(word); - gets(password) - while (words[i][0][0] != '\0') - { - if (strcmp(words[i][0], word) == 0 && strcmp(words[i][1], password) == 0) - { - scanf("%d", &n); - getchar(); - switch(n) - { - case 1: - break; - case 2: - break; - case 3: - break; - default: - printf("鎮ㄨ緭鍏ョ殑鏁板瓧涓嶆纭紝璇疯緭鍏1,2,3涓殑浠绘剰涓涓暟\n"); - break; - } - } - i++; - } - } - else if(n == 0) - { - - } - else - printf("鎮ㄨ緭鍏ョ殑鏁板瓧涓嶆纭紝璇疯緭鍏0,1涓殑鍏朵腑涓涓暟\n"); - } - return 0; -} diff --git a/get_account.c b/get_account.c new file mode 100644 index 0000000..1f0e8a6 --- /dev/null +++ b/get_account.c @@ -0,0 +1,22 @@ +void get_account(FILE *fp)//搜索账号信息模块函数 +{ + int accountnum; + int key; + char name[32]; + float balance; + int i =0,j; + char buffer[BUFFERSIZE]; + int len; + cur_account = 0; + + fseek(fp,0,SEEK_SET); + while(!feof(fp)) // 因为feof()最后会读2遍,所以最后curAccount多加了1 + { + fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance); + accountcollection[cur_account].account = accountnum; + accountcollection[cur_account].key = key; + strcpy(accountcollection[cur_account].name ,name); + accountcollection[cur_account].balance = balance; + cur_account++; + } +} diff --git a/get_info.c b/get_info.c deleted file mode 100644 index eb39893..0000000 --- a/get_info.c +++ /dev/null @@ -1,36 +0,0 @@ -#include - -int main(void) -{ - struct custom - { - char name[20]; - char ID[20]; - char card_number[20]; - float sum; - }a; -FILE *fp; -char c='Y'; -fp=fopen("sum.dat","w");//创建只写文件 -while(c=='Y'||c=='y')//判断循环 -{ - printf("输入姓名:"); - scanf("%s",a.name); - getchar(); - printf("输入身份证号:"); - scanf("%s",a.ID); - printf("输入卡号:"); - scanf("%s",a.card_number); - printf("输入余额:"); - scanf("%f",&a.sum); -fprintf(fp,"%s%s%s%.2f\n",a.name,a.ID,a.card_number,a.sum); - while(1) - { - printf("继续录入?"); - c=getche(); - if(c=='Y'||c=='y'||c=='N'||c=='n') - break; - } -} -fclose(fp); -} diff --git a/insert_account.c b/insert_account.c new file mode 100644 index 0000000..3ad969c --- /dev/null +++ b/insert_account.c @@ -0,0 +1,16 @@ +void insert_account(FILE *fp)//新建账户模块函数 +{ + BANKACCOUNT newaccount; + + printf("请输入账号信息\n"); + printf(">>账号:"); + scanf("%d",&(newaccount.account)); + 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); +} diff --git a/list_account.c b/list_account.c new file mode 100644 index 0000000..4a43e49 --- /dev/null +++ b/list_account.c @@ -0,0 +1,12 @@ +void list_account(FILE *fp)//列出所有账号信息模块函数 +{ + int i =0; + printf("合计%d个账号:\n",cur_account-1);// cur_account减去多加的1 + for(i = 0;i< cur_account-1;i++) + { + printf("账户:%d:\n",i+1); + printf("账号:%d\n",accountcollection[i].account); + printf("姓名:%s\n",accountcollection[i].name); + printf("余额:%.2f\n",accountcollection[i].balance); + } +} diff --git a/search_account.c b/search_account.c new file mode 100644 index 0000000..185596f --- /dev/null +++ b/search_account.c @@ -0,0 +1,17 @@ +int search_account(FILE *fp,int accountnum)//管理员调用模块函数 +{ + 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); + + return 1; + } + } + return 0; +}