求助各位,我尽力了
若要从文件中读取数据放入一个链表中,这样做可以不,但我试了不行啊.
struct player *createplayer(void)
{
struct player *p1,*p2;
struct player *head;
FILE *fp;
int n;
n=0;
fp=fopen("playerdata","rb");
p1=p2=(struct player *)malloc(LEN2);
fread(p1,sizeof(LEN2),1,fp);
head=NULL;
while(p1->next!=NULL)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct player *)malloc(LEN2);
fread(p1,sizeof(LEN2),1,fp);
}
p2->next=NULL;
fclose(fp);
return head;
}