void writetofile(CUST cust[],int *p)
{
FILE *fp;
int i;
if((fp=fopen("银行自助系统.txt","w"))==NULL)
{
printf("打开银行自助系统.txt失败,请重试!\n");
exit(0);
}
for(i=1;i<=*p;i++)
{
fprintf(fp,"%10s%10d%10s%10ld%10ld",cust[i].name,cust[i].account,cust[i].password,cust[i].accnumber,cust[i].id);
}
printf("\n\t写入成功!\n\n");
fclose(fp);
}
//导入数据到文件
void readfromfile(CUST cust[],int *p)
{
FILE *fp;
int i;
if((fp=fopen("银行自助系统.txt","r"))==NULL)
{
printf("打开银行自助系统.txt失败,请重试!\n");
exit(0);
}
fscanf(fp,"%d",p);
for(i=1;i<=*p;i++)
{
fscanf(fp,"%10s",cust[i].name);
fscanf(fp,"%10d",&cust[i].account);
fscanf(fp,"%10s",cust[i].password);
fscanf(fp,"%10ld",&cust[i].accnumber);
fscanf(fp,"%10ld",&cust[i].id);
}
printf("\n\t读入成功!\n\n");
fclose(fp);
}用fscanf导入数据的时候,如果姓名是数字的话第一个数据导入不进去,如果姓名是字母的话整个数据导不进去,求大神解答
- 1 回答
- 0 关注
- 1902 浏览
添加回答
举报
0/150
提交
取消