C语言课程设计求救——文件读取出错

来源:百度知道 编辑:UC知道 时间:2024/06/14 02:33:42
没办法,不做好文件输入输出这简直没法继续做。
问题出在文件载入时读到文件末尾时出错。现在把函数贴在下面,我也知道贴代码不道德,还是先贴了再说。
CLA *load(void)
{FILE *fp1,*fp2,*fp3;
CLA *p1,*head,*tail1=NULL;
BAS *p2,*tail2=NULL;
SALE *p3,*tail3=NULL;
int error1=1,error2=1,error3=1;
if((fp1=fopen("d:/du/CLA.dat","rb"))==NULL)
{printf("Can't load the file %s\n","CLA.dat");
return NULL;}
if((fp2=fopen("d:/du/BAS.dat","rb"))==NULL)
{printf("Can't load the file %s\n","BAS.dat");
return NULL;}
if((fp3=fopen("d:/du/SALE.dat","rb"))==NULL)
{printf("Can't load the file %s\n","SALE.dat");
return NULL;}
while(error1&&!feof(fp1))
{/*创建分类链表*/
if(!ferror(fp1))
{p1=(CLA *)malloc(sizeof(CLA));
if(fread(p1,size_classinfo,1,fp1)!=1)
{printf("Error in reading the file %s\n","

文件最后应该还有\n

代码实在没心看....不过读入问题的话,换个函数试试吧,用freopen试试.

NB 贴这么多 还不看死人了哦 我菜 要不偶给你看看了 不好意思帮不了你了啊 :)