将文件信息读入到单链表中
void scanfCareer(struct career **person){
struct career *p ;
struct career *mp;
struct career *temp;
FILE *fp;
if ((fp=fopen("car.text","r"))==NULL)
{
printf("打开文件失败了……6666!\n");
exit(1);
}
while((fscanf(fp,"%s%s%s",p->c_num,p->c_nam,p->c_car))==3)
{
if(pool !=NULL)
{
mp=pool;
pool=pool->next;
count--;
}
//内存池为空时
else
{
mp=(struct career *)malloc(sizeof(struct career));
if (mp==NULL)
{
printf("Failure 内存分配失败\n");
exit(1);
}
}
mp=p;
if (*person!=NULL)
{
temp=*person;
*person=mp;
mp->next =temp;
}
else
{
*person =p;
p->next =NULL;
}
}
fclose(fp);
}
int main {
struct career *person=NULL;
scanfCareer(&person);
}
打印出的peourson链表只有文件car.text的最后一组数据,怎样更好的解决将文件的内容读入到单链表中???求助!!!