C语言编写的银行管理系统关键代码
#include<stdio.h>
#include<malloc.h>
#include<string.h>
struct band{
char cardname[20];
char name[20];
char mima[6];
double money;
struct band *next;
};
struct band *head,*tail,*temp;
void init(){
head=NULL;
tail=NULL;
temp=NULL;
}
void write(){
FILE *fp=fopen("2.txt","w");
temp=head;
while(temp!=NULL){
fprintf(fp,"%s %s %s %lf\n",temp->cardname,temp->name,temp->mima,temp->money);
temp=temp->next;
}
fclose(fp);
}
void read(){
int flag=0;
FILE *fp=fopen("2.txt","r");
init();
while(1){
temp=(struct band *)malloc(sizeof(struct band));
flag=fscanf(fp,"%s %s %s %lf",temp->cardname,temp->name,temp->mima,&temp->money);
if(flag==-1){
break;
}else{
temp->next=NULL;
if(head==NULL){
head=temp;
tail=temp;
}else{
tail->next=temp;
tail =tail->next ;
}
}
}
fclose(fp);
}
void printUsage(){
printf("\n\t=======欢迎您使用中国银行=======\n");
printf("\n\t=======开卡请按1========\n");
printf("\n\t=======查询请按2========\n");
printf("\n\t=======存钱请按3========\n");
printf("\n\t=======取钱请按4========\n");
printf("\n\t=======转账请按5========\n");
printf("\n\t=======读文档请按6========\n");
printf("\n\t=======修改密码请按7========\n");
printf("\n\t=======结束请按0========\n");
printf("\n\t=======请输入您的选择:========\n");
printf("\n\t======(使用前请先使用读文档功能)========\n");
}
void createCard(){
char a[20];
printf("\n=======欢迎您使用开卡功能:========\n");
printf("\n=======请输入您的卡号:========\n");
scanf("%s",a);
struct band *pd;
pd=head;
while(pd!=NULL){
if(strcmp(a,pd->cardname)==0){
printf("您输入的卡号已存在,请重新输入。\n");
scanf("%s",a);
pd