麻烦大家帮忙看看代码哪里错了
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define N 10
struct books
{char ISBN[20];
char name[20];
float price;
int storage;
int salesquantity;
}book[N];
struct books *p;
int build()
{int i;
FILE *fp;
printf("请依次输入书籍参数,参数间用一个空格隔开,书籍间用回车键隔开\nISBN-------书名-售价-库存量-销量-\n");
for(i=0;i<N;i++)
{scanf("%s",&book[i].ISBN);
scanf("%s",&book[i].name);
scanf("%f",&book[i].price);
scanf("%d",&book[i].storage);
scanf("%d",&book[i].salesquantity);
}
for(i=0;i<N;i++)
{printf("*****%s***** *****%s***** *****%.2f***** *****%d***** *****%d\n",book[i].ISBN,book[i].name,book[i].price,book[i].storage,book[i].salesquantity);
}
if((fp=fopen("resource.bin","wb"))==NULL)
{printf("This file can not be opened!\n");
exit(1);
}
fwrite(p,N*sizeof(struct books),1,fp);
fclose(fp);
return(1);
}
int inquire()
{char key[20];
int i,j,flag=0;
FILE *fp;
again:
if((fp=fopen("resource.bin","r"))==NULL)
{printf("This file can not be opened!\n");
exit(1);
}
fread(p,N*sizeof(struct books),1,fp);
fclose(fp);
printf("请输入查询书籍ISBN号\n");
scanf("%s",&key);
for(j=0;j<N;j++);
{if(strcmp(key,book[j].ISBN)==0)
{flag=1;
printf("%s %s %f %d %d\n",book[j].ISBN ,book[j].name ,book[j].price ,book[j].storage ,book[j].salesquantity );
}
}
if(flag==0)
{printf("未找到相关书籍:1 重新输入ISBN号 2 返回上一级菜单\n");
scanf("%d",&i);
if(i==1) goto again;
if(i==2) return(-1);
}
return(1);
}
void Bubblesort()
{int i,j,p;
struct books temp;
for(i=0;i<N-1;i++)
for(j=N;j>i;j--)
{if(book[i].salesquantity <book[j].salesquantity )
{strcpy(temp.ISBN,book[i].ISBN);
strcpy(book[i].ISBN,book[j].ISBN);
strcpy(book[j].ISBN,temp.ISBN);
strcpy(temp.name ,book[i].name );
strcpy(book[i].name ,book[j].name );
strcpy(book[j].name ,temp.name );
temp.price =book[i].price ;
book[i].price =book[j].price ;
book[j].price =temp.price ;
temp.salesquantity =book[i].salesquantity ;
book[i].salesquantity =book[j].salesquantity ;
book[j].salesquantity =temp.salesquantity ;
temp.storage =book[i].storage ;
book[i].storage =book[j].storage ;
book[j].storage =temp.storage ;
}
}
printf("ISBN-------------书名------价钱---销量---");
for(p=0;p<N;p++)
printf("%s %s %d %d\n",book[p].ISBN ,book[p].name ,book[p].price ,book[p].salesquantity );
}
int call(int (*func)())
{return((*func)());
}
int storage()
{int i,j,n;
struct books temp;
for(i=0;i<N-1;i++)
for(j=N;j>i;j--)
{if (book[i].storage>book[j].storage)
strcpy(temp.ISBN,book[i].ISBN);
strcpy(book[i].ISBN,book[j].ISBN);
strcpy(book[j].ISBN,temp.ISBN);
strcpy(temp.name ,book[i].name );
strcpy(book[i].name ,book[j].name );
strcpy(book[j].name ,temp.name );
temp.price =book[i].price ;
book[i].price =book[j].price ;
book[j].price =temp.price ;
temp.salesquantity =book[i].salesquantity ;
book[i].salesquantity =book[j].salesquantity ;
book[j].salesquantity =temp.salesquantity ;
temp.storage =book[i].storage ;
book[i].storage =book[j].storage ;
book[j].storage =temp.storage ;
}
for(n=0;n<N;i++)
printf("%d %d\n",book[n].price ,book[n].storage);
return (1);
}
int price()
{int i,j,n;
struct books temp;
for(i=0;i<N-1;i++)
for(j=N;j>i;j--)
{if (book[i].price >book[j].price )
strcpy(temp.ISBN,book[i].ISBN);
strcpy(book[i].ISBN,book[j].ISBN);
strcpy(book[j].ISBN,temp.ISBN);
strcpy(temp.name ,book[i].name );
strcpy(book[i].name ,book[j].name );
strcpy(book[j].name ,temp.name );
temp.price =book[i].price ;
book[i].price =book[j].price ;
book[j].price =temp.price ;
temp.salesquantity =book[i].salesquantity ;
book[i].salesquantity =book[j].salesquantity ;
book[j].salesquantity =temp.salesquantity ;
temp.storage =book[i].storage ;
book[i].storage =book[j].storage ;
book[j].storage =temp.storage ;
}
for(n=0;n<N;i++)
printf("%d %d\n",book[n].price ,book[n].storage);
return (1);
}
void purchase()
{int n,m,flag=0;
char aim[20];
error:
printf("请输入购买书籍的ISBN号\n");
scanf("%s",&aim);
for(n=0;n<N;n++)
if(strcmp(book[n].ISBN,aim)==0)
{flag=1;
if(book[n].storage <3)
{printf("库存量不足3本,请尽快购买!\n是否购买:1 是 2 否\n");
scanf("%d",&n);
if(n==1)
{book[n].storage--;
book[n].salesquantity++;
printf("购买成功!\n");
}
}
if(book[n].storage==0)
{printf("库存量不足!\n建议购买热销书!\n");
Bubblesort();
}
}
if(flag==0)
{printf("未找到相关书籍,请重新输入ISBN号\n");
goto error;
}
}
void returngoods()
{char aim[20];
int i,flag=0;
input:
printf("请输入所退书籍ISBN号\n");
scanf("%s",&aim);
for(i=0;i<N;i++)
if(strcmp(aim,book[i].ISBN )==0)
{flag=1;
book[i].salesquantity--;
book[i].storage++;
printf("退货成功!欢迎购买其他书籍!\n");
}
if(flag==0)
{printf("输入错误,请重新输入\n");
goto input;
}
}
void main()
{int i,j1,j2,m,n;
start:
printf("请选择登陆身份:1 管理员 2 用户 3退出系统\n");
scanf("%d",&i);
if(i==1)
{manager:
printf("请选择操作:1 录入书籍 2 销量排行 3 对书籍库存量和价格进行排序 4 返回上一级菜单 5 退出系统\n");
scanf("%d",&j1);
if(j1==1)
{build();
printf("是否返回上一级菜单:1 是 2 否\n");
scanf("%d",&m);
if(m==1)
goto manager;
else if(m==2)
goto end;
}
else if(j1==2)
{Bubblesort();
printf("是否返回上一级菜单:1 是 2 否\n");
scanf("%d",&m);
if(m==1)
goto manager;
if(m==2)
goto end;
}
else if(j1==3)
{sort:
printf("请选择按什么方式排序:1 库存量 2 价格 3返回上一级菜单\n");
scanf("%d",&n);
if(n==3)
goto manager;
else{int(*sort[2])();
sort[0]=storage;sort[1]=price;
call(sort[n]);
printf("是否返回上一级菜单:1 是 2 否\n");
scanf("%d",&m);
if(m==1) goto sort;
if(m==2) goto end;
}
}
else if(j1==4)
goto start;
else if(j1==5)
goto end;
else
{printf("输入错误,请重新选择\n");
goto manager;
}
}
else if(i==2)
{user:
printf("请选择操作:1 查询具体书籍 2 销量排行 3 购买书籍 4 退货 5返回上一级菜单 6 退出系统\n");
scanf("%d",&j2);
if(j2==1)
{m=inquire();
if(m==-1)
goto user;
}
else if(j2==2)
{Bubblesort();
printf("是否返回上一级菜单:1 是 2 否 \n");
scanf("%d",&m);
if(m==1)
goto user;
if(m==2)
goto end;
}
else if(j2==3)
{purchase:
purchase();
printf("是否继续购买书籍:1 是 2 否\n");
scanf("%d",&m);
if(m==1)
goto purchase;
if(m==2)
goto user;
}
else if(j2==4)
{returngoods:
returngoods();
printf("请选择操作:1 继续退货 2 返回上一级菜单 3 退出系统\n");
reput:
scanf("%d",&m);
if(m==1)
goto returngoods;
else if(m==2)
goto user;
else if(m==3)
goto end;
else
{printf("输入错误,请重新输入\n");
goto reput;
}
}
else if(j2==5)
goto start;
else if(j2==6)
goto end;
else
{printf("输入错误,请重新选择\n");
goto user;
}
}
else if(i=3)
goto end;
else
{printf("输入错误,请重新选择\n");
goto start;
}
end:;
}