这是源代码,只完成了一部分,本人新手还请见谅
#include
#include
struct library
{
int no= '\0';
char bookname[50]= "\0";
float bookprice= '\0';
struct library *next;
};
//链表长度为len
struct library *creat_link(int len)
{
struct library *head;
struct library *tmp;
int i;
head = (struct library *)malloc(sizeof(struct library));
tmp = head;
for (i = 1; i < len; ++i)
{
head->next = (struct library*)malloc(sizeof(struct library));
head = head->next;
}
head->next = NULL;
return tmp;
}
void read_file_to_link(struct library* head, FILE* fp)
{
if (head == NULL || fp == NULL)
{
fprintf(stderr, "null pointer");//stderr标准输出(设备)文件,对应终端的屏幕,在屏幕上输出null pointer
exit(EXIT_FAILURE);//表示异常

本文档涉及一个C语言编程问题,程序员尝试将文本文件中的图书信息(编号、书名、价格)读取并存储到链表中,但在实际操作中遇到数据错误,显示为“屯屯屯”。问题出在读取和存储文件内容的函数`read_file_to_link()`上。代码已给出,包括链表创建、文件读取、链表打印等功能。当尝试查看所有图书信息时,程序未能正确解析文件数据。解决方案可能涉及到检查格式化输入语句和内存分配情况。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



