从文件读入信息至链表,我的代码死循环了。求高手指出错误的地方
#include"common.h"void file_link(LIST *head)
{
PLAYER *q; //节点指针
FILE *fp;
if((fp=fopen("playerdata.txt","w"))==NULL)
{
printf("文件无法打开所以无法修改!\n");
exit(1);
}
while(!feof(fp)) //判断文件是否读完
{
//构造节点,将文件的信息放入节点
if(head->first==NULL)
{
head->first=head->last=(PLAYER*)malloc(sizeof(PLAYER));
head->first->next=NULL;
q=head->first;
head->number++;
}
else
{
q=(PLAYER*)malloc(sizeof(PLAYER));
head->last->next=q;
head->last=q;
q->next=NULL;
head->number++;
}
//读取文件信息
fscanf(fp,"%s%s%d%d%d",q->name,q->paler_id,q->wan_number,q->win_numebr,q->fail_number);
}
fclose(fp);
}