void?writetofile(CUST?cust[],int?*p)
{
FILE?*fp;
int?i;?
if((fp=fopen("銀行自助系統(tǒng).txt","w"))==NULL)
{
printf("打開銀行自助系統(tǒng).txt失敗,請(qǐng)重試!\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);
}
//導(dǎo)入數(shù)據(jù)到文件?
void?readfromfile(CUST?cust[],int?*p)
{
FILE?*fp;
int?i;
if((fp=fopen("銀行自助系統(tǒng).txt","r"))==NULL)
{
printf("打開銀行自助系統(tǒng).txt失敗,請(qǐng)重試!\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導(dǎo)入數(shù)據(jù)的時(shí)候,如果姓名是數(shù)字的話第一個(gè)數(shù)據(jù)導(dǎo)入不進(jìn)去,如果姓名是字母的話整個(gè)數(shù)據(jù)導(dǎo)不進(jìn)去,求大神解答
- 1 回答
- 0 關(guān)注
- 1962 瀏覽
添加回答
舉報(bào)
0/150
提交
取消