把一个文件中的数据输出为链表解决思路
把一个文件中的数据输出为链表
把一个文件中的数据输出为链表的函数
伪代码如下
struct a* read2(FILE* fp)//函数参数为文件指针
{
int ch;
int i=0;
struct a* head,*p1,*p2;
ch=fgetc(fp);
if(ch==EOF)//文件为空的话返回空指针
return NULL;
fseek(fp,0L,0);
head=p1=p2=(struct a*)malloc(sizeof(struct a));
fscanf();//读取数据
p1->next=NULL;
while(!feof)
{
p2=p1;
p1=(struct a*)malloc(sizeof(struct a));
p2->next=p1;
fscanf();//读取数据
p1->next=NULL;
}
free(p2);
return head;
}
可是输出的不是链表,连接不起来,求高手指错
------解决方案--------------------
while(!feof)//这里错了,feof没有参数,应该是while(!feof(fp))
把一个文件中的数据输出为链表的函数
伪代码如下
struct a* read2(FILE* fp)//函数参数为文件指针
{
int ch;
int i=0;
struct a* head,*p1,*p2;
ch=fgetc(fp);
if(ch==EOF)//文件为空的话返回空指针
return NULL;
fseek(fp,0L,0);
head=p1=p2=(struct a*)malloc(sizeof(struct a));
fscanf();//读取数据
p1->next=NULL;
while(!feof)
{
p2=p1;
p1=(struct a*)malloc(sizeof(struct a));
p2->next=p1;
fscanf();//读取数据
p1->next=NULL;
}
free(p2);
return head;
}
可是输出的不是链表,连接不起来,求高手指错
------解决方案--------------------
while(!feof)//这里错了,feof没有参数,应该是while(!feof(fp))