运行结果及报错内容 始终返回一个地址
#include"addressBook.h"
struct bookinfo* readfile(FILE*infile)
{
struct bookinfo *p,*head;
head=NULL;
p=(struct bookinfo*)malloc(len);
while(!feof(infile)) //字符型不用取地址
{
fscanf(infile,"%s%s%s%s%f%d\n",p->number,p->name,p->author,p->press,&p->price,&p->stocknum);
p->next=head;
head=p;
p=(struct bookinfo*)malloc(len);
}
p->next=NULL;
printf("录入完成");
return head;
}
void showall(struct bookinfo*p)
{
while(p!=NULL)
{
printf("%s %s %s %s %f %d\n",p->number,p->name,p->author,p->press,p->price,p->stocknum);
p=p->next;
}
}
#include"addressbook.h"
void menu()
{
int num;
printf("***************欢迎来到图书管理系统*******************\n");
printf("***************请输入您想进行的操作*******************\n");
printf(" 1 浏览现存图书信息\n");
printf(" 2 查找相关书籍\n");
printf(" 3 增加书籍\n");
printf(" 4 删除书籍\n");
printf(" 5 修改某本书籍信息\n");
printf(" 6 借阅书籍\n");
}
//图书管理员和图书借阅者 分别针对两种身份设计两种不同的界面
//清屏
//模糊查找
//针对不同信息 进行关键字检索
//书籍的编号,作者,名字必须填写 库存必须录入 ,其余的可以不填写
//每借阅一次 会在文档中留下最后一次被借阅的时间
#include"addressBook.h"
int main()
{
struct bookinfo *p;
FILE* infile;
int input=0;
char a[20];
gets(a); //书籍信息.txt
infile=openfile(a);
p=readfile(infile);
// do
// { menu();
// printf("请选择您要执行的操作");
// scanf("%d",&input);
// switch (input)
// {
// case 1:system("cls");
// showall(p);
// printf("按任意键 返回主菜单");
// fflush(stdin);
// getchar();
// system("cls");
// break;
// case 2:;break;
// case 3:;break;
// case 5:;break;
// case 6:;break;
// case 7:;break;
// default:printf("输入格式错误,请重新输入");
// scanf("%d",&input);
// break;
// }
// }while(input);
return 0
}
#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);
}
#ifndef H_ADDRESSBOOK_H
#define H_ADDRESSBOOK_H
//文件包含
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<malloc.h>
#include<ctype.h>
#include<string.h>
//宏定义
#define len sizeof(struct bookinfo*)
//结构体
struct bookinfo //用于存储图书信息
{
char number[20];
char name[20];
char author[20];
char press[20];
float price;
int stocknum;
struct bookinfo* next;
};
//函数原型
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);//用于对某一本书的信息作修改
#endif