今日在初学文件录入到链表的时候
通过先打开文件在录入到链表
一开始运行的时候没有问题 但过了一段时间不知道为什么运行时就不会接着跑下去了是因为不小心改到哪里了吗?
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<malloc.h>
#include<ctype.h>
#include<string.h>
//函数原型
void showall(struct bookinfo*head); //显示当前的图书信息
void menu(); //打印菜单
FILE* openfile(char *name);//用于函数前期打开文件
struct bookinfo* readfile(FILE*);
void search(struct bookinfo*head);//用于寻找某一数据
void addbook(struct bookinfo*head);//用于增加某一本书的信息 返回值待确定??????
void delbook(struct bookinfo*head);//用于删除某一本书的信息
void editbook(struct bookinfo*head);//用于对某一本书的信息作修改
int main()
{
struct bookinfo *p;
FILE* infile;
int input=0;
char a[20];
gets(a); //书籍信息.txt
infile=openfile(a);
p=readfile(infile);
}
#include"addressBook.h"
FILE *openfile(char* name)
{
int flag=1;
char b;
FILE*infile;
while(flag)
{
flag=0;
if((infile=fopen(name,"r"))==NULL)
{
printf("打开失败\n 请重新输入\n");
printf("是否愿意重新输入图书管理名 y or n");
b=getchar();
if(b=='n')
exit(1);
else
scanf("%s",name);
flag=1;
}
}
printf("打开成功\n");
return (infile);
}
struct bookinfo*readfile(FILE*infile)
{
struct bookinfo *p,*head;
head=NULL;
p=(struct bookinfo*)malloc(len);
while(fscanf(infile,"%s%s%s%s%f%d",p->number,p->name,p->author,p->press,&p->price,&p->stocknum)!=EOF) //字符型不用取地址
{
p->next=head;
head=p;
p=(struct bookinfo*)malloc(len);
}
free(p);
printf("录入完成");
return head;
}
问题可能出在第三个函数上