#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//函数声明
void spent(struct Library *a);
void key(char im[20]);
void input(struct Library *m);
void Lookfor(struct Library *a, char im[20]);
struct Library
{
char Bookname[20];
char Bookauthor[20];
struct Library *library;
};
void input(struct Library *m)
{
char a;
printf("是否加入书籍(Y/N):");
scanf("%c",&a);
getchar();
if(a=='Y')
{
spent(m);
printf("请输入书名:");
scanf("%s",m->Bookname);
getchar();
printf("请输入作者:");
scanf("%s",m->Bookauthor ) ;
getchar();
input(m->library );
}
else
{
return ;
}
}
void key(char im[20])
{
printf("请输入你要找的书的书名或者作者:");
scanf("%s",im);
getchar();
}
void Lookfor(struct Library *a, char im[20])
{
if(a!=NULL)
{
if(strcmp(a->Bookauthor,im)==0 || strcmp(a->Bookname,im)==0)
{
printf("已检索,你要搜的书的作者为%s,书名为%s\n",a->Bookauthor,a->Bookname);
return Lookfor(a->library, im);
}
else
{
Lookfor(a->library, im);
}
}
else
{
printf("抱歉,无此书");
return ;
}
}
void spent(struct Library *a)
{
a->library =(struct Library *)malloc (sizeof(struct Library));
}
int main(void)
{
struct Library *library=NULL;
library=(struct Library *)malloc (sizeof(struct Library));
input(library);
char im[20];
key(im);
Lookfor(library, im);
return 0;
}
希望这些修改能够帮助你完善你的程序,让它更加完善和健壮。