该系统是采用了细分各个功能模块,分别在main.c文件中调用。
开发环境是Win7,Netbeans8.0.2
这是main.c
#include
#include
#include
#include "bmenu.h"
#include "search_allinformation.h"
typedef struct bookinfo {
char num[20]; /*图书编号*/
char name[40]; /*书名*/
char author[40]; /*作者*/
char publish [40]; /*出版社*/
double price; /*价格*/
} bi[40];
int w = 0; /*定义一个全局变量,用来记录bookinfo.txt文件中的数据个数*/
int main() {
int i = 0;
int choice1;
FILE fp;
printf(" * ***************************** \n");
printf(" * 欢迎进入图书馆信息管理系统 *\n");
printf(" * ***************************** \n");
fp = fopen("E:\BookInfo.txt", "r");
if (fp == NULL) {
printf("Can not open the file !\n");
exit(0);
}
while (!feof(fp)) {
fscanf(fp, "%s%s%s%s%lf", /调用函数将文件中的数据读入结构变量中*/
&bi[i].num,&bi[i].name,&bi[i].author, &bi[i].publish, &bi[i].price);
i++;
}
w = i - 1;
fclose(fp);
do {
bmenu();
scanf("%d", &choice1);
switch (choice1) {
case 1:
search_allinformation(bookinfo &bi);
break;
case 2:
check_bookinformation(b);
break;
case 3:
add_bookinformation(b);
break;
case 4:
delete_bookinformation(b);
break;
case 5:
borrow_book(b);
break;
case 0:
break;
}
} while (choice1 != 0);
printf("谢谢使用!\n");
return 0;
}
这是bmenu.c
#include
void bmenu() {
printf("################################################################################");
printf(" 功能选项: \n");
printf(" 1:查看全部图书信息 \n");
printf(" 2:查找图书信息 \n");
printf(" 3:添加图书信息 \n");
printf(" 4:删除图书信息 \n");
printf(" 5:借阅图书 \n");
printf(" 0:退出系统 \n");
printf("################################################################################");
printf("请选择操作:");
}
这是bmenu.h
#ifndef BMENU_H
#define BMENU_H
#ifdef __cplusplus
extern "C" {
#endif
void bmenu();
#ifdef __cplusplus
}
#endif
#endif /* BMENU_H */
这是search_allinformation.c
#include
typedef struct list {
char num[20]; /*图书编号*/
char name[40]; /*书名*/
char author[40]; /*作者*/
char publish [40]; /*出版社*/
double price; /*价格*/
};
struct list b[40];
void search_allinformation(struct list b[],int w) {
int i;
int m = w;
printf(" ####################################\n");
printf(" # 查看全部图书信息! #\n");
printf(" ####################################\n");
printf("图书的相关信息: 编号 书名 作者 出版社 价格\n");
for (i = 0; i < m; i++) {
printf(" %s %s %s %s %.2f\n", /*将数据输出到屏幕中*/
b[i].num, b[i].name, b[i].author, b[i].publish, b[i].price);
}
printf("################################################################################\n");
}
这是search_allinformation.h
#ifndef SEARCH_ALLINFORMATION_H
#define SEARCH_ALLINFORMATION_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct list {
char num[20]; /*图书编号*/
char name[40]; /*书名*/
char author[40]; /*作者*/
char publish [40]; /*出版社*/
double price; /*价格*/
};
struct list b[40];
void search_allinformation(struct list b[]);
#ifdef __cplusplus
}
#endif
#endif /* SEARCH_ALLINFORMATION_H */
出现的问题如下: