关于文件读写的问题
我想要做一个关于银行管理的程序,该程序将会包含创建用户,更改用户存款的功能.其中用户的结构体有如下定义:
struct inf
{
long cardnumber;
long password;
char fname[21];
char lname[21];
float money;
};
创建用户的功能已经编好,如下代码:
void create(void)
{
FILE *fp;
fp=fopen(fp,"a+b");
auto struct user;
auto flag=0;
auto char answer;
while(flag==0)
{
create_menu();
user.cardnumber=create_cardnumber();
user.password=create_password
gotoxy(1,22);
printf("Please enter your first name:");
gets(user.fname);
printf("Please enter your last name:");
gotoxy(1,22);
gets(user.lname);
user.money=get_money();
gotoxy(1,22);
printf("Name:%s %s",user.fname,user.lname);
gotoxy(1,22);
printf("Cardnumber:%ld",user.cardnumber);
gotoxy(1,22)
printf("Password:%ld",user.password);
gotoxy(1,22);
printf("Money:.4f",user.money);
gotoxy(1,25);
printf("Are you sure?(Y or y to continue,q to quit)");
if(answer=getchar()!='Y'&&answer=getchar()!='y'
&&answer=getchar()!='Q'&&answer!='q')
system("cls");
else if(answer=getchar()=='Y'&&answer=getchar()=='y')
{
fwrite(&user,sizeof(struct inf),1,fp);
flag=1;
}
else
break;
}
fclose(fp);
system("cls");
if(flag==1)
{
gotoxy(6,22);
printf("You have successfully created a new user.\n");
}
else
{
gotoxy(6,22);
printf("You fail to create a new user.\n");
}
}
而用户的登陆及修改特定用户的资料时,却无从下手,我的程序只完成到这,,代码如下:
int login(void)
{
FILE *fp;
extern struct inf user,
auto struct inf temp;
auto int flag=0;
auto int size=sizeof(struct inf);
fp=fopen("data","rb");
rewind(fp);
while(flag==0)
{
login_menu();
temp.cardnumber=get_cardnumber();
temp.password=get_password();
if((user.cardnumber==temp.cardnumber)&&
(user.password==temp.password))
flag=1;
else if(fseek(fp,ptr,CUR)!=0)
break;
else
}
}
void inquiry(FILE *fp,struct inf *pst)
{
gotoxy(4,25);
printf("Welcome to China Construction Bank");
gotoxy(1,22);
printf("Name:%s %s",pst->fname,pst->lname);
gotoxy(1,22);
printf("Cardnumber:%ld",pst->cardnumber);
gotoxy(1,22);
printf("Money:%.4f",pst->money);
}
void despoit(FILE *fp,struct inf *pst)
{
auto int money;
gotoxy(4,25);
printf("Welcome to China Construction Bank");
gotoxy(1,22);
printf("How much do yo want to despoit?\n");
while(scanf(".4f",&money!=1))
{
gotoxy(1,22);
printf("You may enter an invalid money.");
gotoxy(1,22);
printf("How much do yo want to despoit?\n");
}
pst->money+=money;
}
void teller(FILE *fp,struct inf *pst)
{
auto int money;
gotoxy(4,25);
printf("Welcome to China Construction Bank");
gotoxy(1,22);
printf("How much do yo want to teller?\n$");
while(scanf(".4f",&money!=1)&&money>(pst->money))
{
if(scanf(".4f",&money!=1))
{
gotoxy(1,22);
printf("You may enter an invalid money.");
}
else
{
gotoxy(1,22);
printf("You don't have enough money.");
gotoxy(1,22);
printf("How much do yo want to despoit?\n");
}
pst->money-=money;
}
希望高手能帮助一下