来大佬帮我看看,我这小的信息管理系统有什么问题,为什么用编译器运行到半路,程序就停止工作了
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#define SIZE 5
struct book_type
{
char name[15];
char author[15];
int date;
int pages;
float price;
}book[SIZE];
void input();
void searching();
void output();
void save();
void order();
int num;
int main()
{ while(1)
{ printf("******************************************\n");
printf("欢迎使用图书数据库系统\n");
printf("请根据以下提示进行操作\n");
printf("录入图书信息请输入数字1\n");
printf("搜索图书请输入数字2\n");
printf("输出所有图书的信息请输入数字3\n");
printf("退出系统请输入数字0\n");
printf("******************************************\n");
switch(getchar())
{
case'1': input(); break;
case'2': searching();break;
case'3': output(); break;
case'0': exit(0);
}
}
return 0;
}
void input()
{ int i=0,YN=0;
while(i<SIZE)
{ printf("******请录入图书的信息******\n");
printf("书名 作者 出版年份 页数 价格\n");
scanf("%15s%15s%d%d%f",book[i].name,book[i].author,book[i].date,
&book[i].date,&book[i].pages,&book[i].price);
printf("继续录入? \nY(1) N(0)\n");
scanf("%d",&YN);
if(YN==0)break;
i++;
}
order();
save();
return;
}
void save()
{
FILE*fp;
int i;
fp=fopen("book_list","wb");
for(i=0;i<SIZE;i++)
{
if(fwrite(&book[i],sizeof(struct book_type),1,fp)!=1)
printf("file write error\n");
}
printf("\nfile save\n");
fclose(fp);
return;
}
void output()
{
FILE *fp;
int i;
fp=fopen("book_list","rb");
printf("书名 作者 出版年份 页数 价格\n");
for(i=0;i<SIZE;i++)
{
fread(&book[i],sizeof(struct book_type),1,fp);
printf("%-15s%-15s%-6d%-6d%-6d\n",book[i].name,book[i].author,book[i].date,
&book[i].date,&book[i].pages,&book[i].price);
}
fclose(fp);
return;
}
void searching()
{
char nm[15];
int i,aa;
FILE*fp;
fp=fopen("book_list","rb");
for(i=0;i<SIZE;i++)
{
fread(&book[i],sizeof(struct book_type),1,fp);
}
printf("请输入书名\n");
scanf("%s",nm);
for(i=0;i<SIZE;i++)
if(strcmp(nm,book[i].name)==0)
{ printf("***************************************");
printf("书名 作者 出版年份 页数 价格\n");
printf("%-15s%-15s%-6d%-6d%-6d\n",book[i].name,book[i].author,
&book[i].date,&book[i].pages,&book[i].price);
printf("***************************************");
break;
}
return;
}
void order()
{
struct book_type chane;
int i,j;
for(j=0;j<SIZE;j++)
for(i=0;i<SIZE-j;i++)
if(book[i].date>book[i+1].date)
{
strcpy(chane.name,book[i].name);strcpy(chane.author,book[i].author);
chane.date=book[i].date;chane.pages=book[i].pages;
chane.price=book[i].price;//
strcpy(book[i].name,book[i+1].name);strcpy(book[i].author,book[i+1].author);
book[i].date=book[i+1].date;book[i].pages=book[i+1].pages;
book[i].price=book[i+1].price;//
strcpy(book[i+1].name,chane.name);strcpy(book[i+1].author,chane.author);
book[i+1].date=chane.date;book[i+1].pages=chane.pages;
book[i+1].price=chane.price;//
}
return
}