C语言新人,作atm遇到问题,看了好久不知道哪里错了。求大神帮忙
大一学生正在做查询功能,查询的那个功能最后
printf("在%d存入了%d",b.inyear,b.inmoney);
printf("在%d取出了%d",b.outyear,b.outmoney);
输出的是4个都是-858993460.不知道是哪里错了,又大神帮我一下吗谢谢
#include<stdio.h>
void newid();
void save();
void draw();
void research();
struct record
{
int inyear;
int outyear;
int inmoney;
int outmoney;
int nowmoney;
};
struct id
{
char number[15];//用户名
int balance;//余额
};
void newid()
{
struct id newone;
char filename[15];
FILE *a,*b;
printf("请输入要新建的用户名:");
scanf("%s",filename);
if((a=fopen(filename,"rb+"))!=NULL)
{
printf("用户名已存在");
fclose(a);
return;
}
b=fopen(filename,"wb+");
printf("请再次输入新建用户名:");
scanf("%s",newone.number);
printf("请输入账号余额:");
scanf("%d",&newone.balance);
fwrite(&newone,sizeof(struct id),1,b);
fclose(b);
printf("输入成功");
}
void save()
{
FILE *in;
char filename[15];
struct id a,b;
struct record c;
printf("请输入用户名:");
scanf("%s",filename);
if((in=fopen(filename,"rb+"))==NULL)
{
printf("输入错误,该用户不存在");
fclose(in);
return;
}
printf("请再次输入用户名:");
scanf("%s",a.number);
fread(&b,sizeof(struct id),1,in);
printf("输入你的存款日期");
scanf("%d",&c.inyear);//日期
printf("输入存钱金额");
scanf("%d",&c.inmoney);
c.nowmoney=b.balance+c.inmoney;
a.balance=c.nowmoney;
printf("操作成功\n");
printf("当前账号余额为:%d",c.nowmoney);
fwrite(&c,sizeof(struct record),1,in);
fseek(in,0L,0);
fwrite(&a,sizeof(struct id),1,in);
fclose(in);
}
void draw()
{FILE*in;
struct id a,b;
struct record c;
char filename[15];
printf("请输入用户名:");
scanf("%s",filename);
if((in=fopen(filename,"rb+"))==NULL)
{
printf("输入错误,该用户名不存在");
fclose(in);
return;
}
printf("请再次输入用户名:");
scanf("%s",a.number);
fread(&b,sizeof(struct id),1,in);
printf("请输入取款日期");
scanf("%d",&c.outyear);
printf("请输入取款金额:");
scanf("%d",&c.outmoney);
c.nowmoney=b.balance-c.outmoney;
a.balance=c.nowmoney;
printf("操作成功");
printf("当前余额为%d",c.nowmoney);
fwrite(&c,sizeof(struct record),1,in);
fseek(in,0L,0);
fwrite(&a,sizeof(struct id),1,in);
fclose(in);
}
void research()
{ FILE *in;
char filename[15];
struct id a;
struct record b;
printf("请输入账号名");
scanf("%s",filename);
if((in=fopen(filename,"rb+"))==NULL)
{
printf("该用户名不存在");
fclose(in);
return;
}
fread(&a,sizeof(struct id),1,in);
fread(&b,sizeof(struct record),1,in);
printf("当前账号余额为%d",a.balance);
printf("在%d存入了%d",b.inyear,b.inmoney);
printf("在%d取出了%d",b.outyear,b.outmoney);
fclose(in);
}
int main()
{
newid();
save();
draw();
research();
return 0 ;
}