今日在练习文件录入到链表的时候
通过先打开文件再录入到链表
但是为什么程序陷入死循环呢?
int readgoods()
{
FILE *fp;
int i;
int t,y;
double u;
char z[20],x[20];
if((fp = fopen("D:\\f01\\a02.txt","rb")) == NULL)
{
printf("打开文件失败!qwq\n");
exit(0);
}
pgoods q,p;
p=L;
while(fscanf ( fp,"%d \t\t%s \t\t%s \t\t%d \t\t%.2lf \n",&t,z,&x,&y,&u)!=EOF)
{
q = (goods *)malloc(sizeof(goods));
q->num=t;
strcpy(q->name,z);
strcpy(q->sort,x);
q->amount=y;
q->price=u;
q->next=NULL;
p->next=q;
p=q;
}
fclose(fp);
}