请问C语言如何把链表存入文件,从文件读取到链表
Consumer* read_list()
{
FILE *fp;
if ((fp = fopen("CONSUMER.dat", "rb")) == NULL)
{
printf("无法读取 CONSUMER.dat\n");
return NULL;
}
int sign;
Consumer *s,*p,*head;
head= (Consumer*)malloc(SIZE_C);
if (head == NULL)
{
printf("读取失败!内存空间申请不足!\n");
return NULL;
}
fseek(fp, 0, SEEK_END);
if (ftell(fp) == 0)
{
return NULL;
}
p = head;
p->next = NULL;
while (feof(fp))
{
s = (Consumer*)malloc(SIZE_C);
fread(s, SIZE_C, 1, fp);
p->next = s;
p = s;
p->next = NULL;
}
fclose(fp);
return head;