为什么fscanf没有读取正确的输出? [英] Why is fscanf not reading proper output?
本文介绍了为什么fscanf没有读取正确的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码给了我一个巨大的问题,似乎无法找出原因。
我将一些信息存储到一个文件中,我想把它读回去,但它保留了读出9个变量而不是14个,我不知道为什么。
读出代码(我遗漏了一些代码以保持简短)
I have the following code that is giving me a Huge problem, and cant seem to figure out why.
I stored some information to a file and i want to read it out back but it keeps on reading out 9 variables instead of the 14 and i dont know why.
Reading out code ( i have left out some of the code as to keep it short)
int FindInfo(FILE *fp,Ca_Info *emp,int regnum,int upd)
{
int tempreg,choice;
Ca_Info tempstr;
trans temptstr;
int hm;
if (regnum>1000)
{
tempreg=regnum;
while (1)
{
hm=fscanf(fp,"%s %d %d %s %d %s %d %s %d %d %f %f %s %s",temptstr.transnum,&tempstr.regnum,&temptstr.d_Lic,temptstr.c_Nme,&temptstr.dte.DD,temptstr.dte.sls,&temptstr.dte.MM,temptstr.dte.sls1,&temptstr.dte.YY,&temptstr.time,&temptstr.ins_Cost,&temptstr.rnt_Cost,temptstr.cre_Crd,tempstr.status);
if(feof(fp))
{
return 1;
}
if((atoi(temptstr.transnum)-regnum)==0)
{
return 0;
}
else
{
return 1;
}
}
}
代码以这种格式编写:
Code was written in this format:
strcpy(rting.status,"Out");
fflush(rfp);
fprintf(rfp,"%s %d %d %s %d%s%d%s%d %d %.2f %f %s %s\n",ruc.transnum,rting.regnum,ruc.d_Lic,ruc.c_Nme,ruc.dte.DD,ruc.dte.sls,ruc.dte.MM,ruc.dte.sls1,ruc.dte.YY,ruc.time,ruc.ins_Cost,ruc.rnt_Cost,ruc.cre_Crd,rting.status);
regch=rting.regnum;
Update(regch);
fclose(rfp);
fclose(verfp);
这是打印时的输出文件
174094 1 123456 Alec 12 // 8 // 2014 20 400.00 600.000000 2222222 Out
This is the ouput in file when printed
174094 1 123456 Alec 12//8//2014 20 400.00 600.000000 2222222 Out
推荐答案
这篇关于为什么fscanf没有读取正确的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文