C语言的程序运行问题,帮忙看看,为什么编译没有错误,却一运行就崩溃?
#include<stdio.h>structbooks{charname[100];intnumber;floatprice;charauthor[100];intst...
#include <stdio.h>
struct books
{
char name[100];
int number;
float price;
char author[100];
int state;
char student;
int sex;
int studentnumber;
}book[10];
int i,x,j,n;
table()
{
printf(" **************************************************\n");
printf(" 欢迎使用图书管理系统 \n");
printf(" 请选择你所想执行的功能 \n");
printf(" 1.输入新进书籍信息 \n");
printf(" 2.查询图书 \n");
printf(" 3.删除图书信息 \n");
printf(" 4.借书 \n");
printf(" 5.还书 \n");
printf(" **************************************************\n");
}
putin()
{
FILE *fp;
fp=fopen("book.txt","w+");
for(i=0;i<=10;i++)
fscanf(fp,"%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
scanf("%d",x);
scanf("%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
for(i=0;i<=10;i++)
fprintf(fp,"%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
fclose(fp);
}
search()
{
FILE *fp;
fp=fopen("book.txt","a+");
scanf("%d",&i);
for(x=0;x<=i;x++)
fscanf(fp,"%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
fclose(fp);
if(book[x].state==0)
printf("%s,%d,%f,%s,此书现藏于馆中",book[i].name,&book[i].number,&book[i].price,book[i].author);
else
if(book[x].sex==1)
printf("%s,%d,%f,%s,已借出,%s,girl,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,book[i].student,book[i].studentnumber);
else
printf("%s,%d,%f,%s,已借出,%s,boy,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,book[i].student,book[i].studentnumber);
}
main ()
{
table();
scanf("%d",n);
switch(n)
{
case 1:putin();
break;
case 2:search();
break;
}
return 0;
} 展开
struct books
{
char name[100];
int number;
float price;
char author[100];
int state;
char student;
int sex;
int studentnumber;
}book[10];
int i,x,j,n;
table()
{
printf(" **************************************************\n");
printf(" 欢迎使用图书管理系统 \n");
printf(" 请选择你所想执行的功能 \n");
printf(" 1.输入新进书籍信息 \n");
printf(" 2.查询图书 \n");
printf(" 3.删除图书信息 \n");
printf(" 4.借书 \n");
printf(" 5.还书 \n");
printf(" **************************************************\n");
}
putin()
{
FILE *fp;
fp=fopen("book.txt","w+");
for(i=0;i<=10;i++)
fscanf(fp,"%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
scanf("%d",x);
scanf("%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
for(i=0;i<=10;i++)
fprintf(fp,"%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
fclose(fp);
}
search()
{
FILE *fp;
fp=fopen("book.txt","a+");
scanf("%d",&i);
for(x=0;x<=i;x++)
fscanf(fp,"%s,%d,%f,%s,%d,%s,%d,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,&book[i].state,book[i].student,book[i].sex,book[i].studentnumber);
fclose(fp);
if(book[x].state==0)
printf("%s,%d,%f,%s,此书现藏于馆中",book[i].name,&book[i].number,&book[i].price,book[i].author);
else
if(book[x].sex==1)
printf("%s,%d,%f,%s,已借出,%s,girl,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,book[i].student,book[i].studentnumber);
else
printf("%s,%d,%f,%s,已借出,%s,boy,%d",book[i].name,&book[i].number,&book[i].price,book[i].author,book[i].student,book[i].studentnumber);
}
main ()
{
table();
scanf("%d",n);
switch(n)
{
case 1:putin();
break;
case 2:search();
break;
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询