求解,怎么把文本数据读取到链表,
改了好久。还是读取不了。求帮忙改改。。谢谢
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <windows.h>
struct Book
{
int num; //保存的编号
char bname[50]; //保存书名
char writer[20]; //作者名
char press[50]; //出版社
char time[20]; //出版时间
float price;
struct Book * pNext;
};
book * download()
{
FILE *fp;
book *head, *p1;
head = NULL;
if ((fp = fopen("图书.txt", "a")) == NULL)
{
printf("File open error!\n");
system("pause");
exit(0);
}
while (!feof(fp))
{
p1 = (book *)malloc(sizeof(book));
fscanf(fp, "%d %s %s %s %s %f\n", &p1->num, p1->bname, p1->writer, p1->press, p1->time, &p1->price);
if (head == NULL)
{
head = p1;
}
p1 = p1->pNext;
}
fclose(fp);
return head;
}
[此贴子已经被作者于2016-3-13 14:57编辑过]