无错误,运行时停止工作
#include<stdio.h>#include<conio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char name[40];
char author[40];
char place[40];
}Book;
Book * book=NULL;
int current=0;
int total=100;
void insert()
{
if(current>total)
{
printf("当前存储空间不足,请输入图书量以分配图书空间\n");
printf("PS:当前图书空间为%d",total);
scanf("%d",&total);
printf("修改成功,当前空间为%d",total);
}
printf("请输入图书名字");
scanf("%s",&book[current].name);
printf("请输入图书作者");
scanf("%s",&book[current].author);
printf("请输入图书出版社");
scanf("%s",&book[current].place);
current++;
}
void query()
{
char *word;
printf("请输入搜索关键字");
int hasfound = 0;
scanf("%s",word);
int i;
char *s;
for(i=0;i<current;i++)
{
s=strstr(book[i].name,word);
if(s == NULL)
{
s=strstr(book[i].author,word);
if(s == NULL)
{
s=strstr(book[i].place,word);
if(s != NULL)
printf("%s,%s,%s",book[i].name,book[i].author,book[i].place);
hasfound=1;
}
printf("%s,%s,%s",book[i].name,book[i].author,book[i].place);
hasfound=1;
}
printf("%s,%s,%s",book[i].name,book[i].author,book[i].place);
hasfound=1;
}
if(hasfound=0)
printf("不存在");
}
void del()
{
int hasfound = 0;
int i;
printf("请输入要删除的书名:");
char name[40];
scanf("%s", name);
for (i=0; i<current; i++)
{
if (strcmp(book[i].name, name) == 0)
{
hasfound = 1;
memmove(&book[i], &book[i+1], (current-1-i)*sizeof(Book));
printf("删除成功\n");
current--;
//return ; //0;
}
}
if(hasfound == 0)
printf("该书不存在\n");
}
int main()
{
char choice;
printf(" 程序功能\n");
printf(" 1:录入图书信息\n");
printf(" 2:查询图书信息\n");
printf(" 3:修改图书信息\n");
printf("请选择:");
choice=getchar();
switch(choice)
{
case '1':
insert();
break;
case '2':
query();
break;
case '3':
del();
break;
default:
printf("请不要调皮-_-");
return 0;
}
return 0;
}