总共有八个功能:1.借书,2.还书,3.查看图书,4.查询图书,5.增加图书,6.删除图书,7.学生借书情况查询,8.退出系统。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NAME_LEN 50//定义scanf输入的汉字长度
struct Student//定义学生
{
char name[32];
int id;
char count; //借书的本数;
char book[5][20];//借的哪些书
};
typedef struct Student stu;
stu *g_student[1000];
struct Book
{
char name[32];
int count; //剩余本数;
};
typedef struct Book book;
book *g_book[1000];
int bookcount = 8; //书的种类
int studentcount = 0;//可以借书的人
int menu()
{
printf(" 菜 单 \n");
printf("********************************************\n");
printf("1.借阅书籍 2.归还书籍\n");
printf("3.查询书籍 4.查看书籍 \n");
printf("5.增加书籍 6.删除书籍 \n");
printf("7.学生借书情况查询 8.退出系统\n");
printf("*********************************************\n");
printf("请输入你的选择\n");
int num;
while (scanf_s("%d", &num) != 1 || num < 0 || num > 8)
{
printf("你的选择有误,请重新选择\n");
system("pause");
fflush(stdin);//清空缓冲区
}
return num;
}
void Init1()
{
int i;
for (i = 0; i < bookcount; i++)
{
g_book[i] = (book*)malloc(sizeof(book) * 10);
if (NULL == g_book[i])
{
printf("内存申请失败\n");
break;
}
}
strcpy_s(g_book[0]->name, "语文");
strcpy_s(g_book[1]->name, "数学");
strcpy_s(g_book[2]->name, "英语");
strcpy_s(g_book[3]->name, "历史");
strcpy_s(g_book[4]->name, "地理");
strcpy_s(g_book[5]->name, "物理");
strcpy_s(g_book[6]->name, "化学");
strcpy_s(g_book[7]->name, "生物");
g_book[0]->count = 3;
g_book[1]->count = 4;
g_book[2]->count = 2;
g_book[3]