代码仅供参考:
#include "stdio.h"
#include "conio.h"
struct books
{
char *name;
char *press;
char *author;
float price;
};
struct books lib[]={{"C language","UESTC","Zhuang San",12.50},{"PASCAL","UESTC","Li Si",10.00},{"English Reading","UESTC","Wang wu",8.00},{"########","#####","######",0}};//由于篇幅有限,这里只给出三本书的信息
main()
{
find();
printf("Press any key continue...\n");
getch();
}
//图书查询子函数
find()
{
struct books *p;
char sm[100];
int i=0;
p=&lib[i];
printf("Please input the name of books:\n");
gets(sm);
printf("The information of the books:\n");
while(p->price!=0)//用p->price成员的值控制循环
{
if(strcmp(p->name,sm)==0)
{
printf("%18s%8s%8s%7.2f\n",p->name,p->author,p->press,p->price);
break;//当字符比较函数值为0,表明该书已找到,打印并跳出循环
}
i++;//否则将下标加1移向下一元素
p=&lib[i];//让指针再指向这一元素后继续查找
}
if(p->price==0)//p->price=0,表明整个书库都已查完并没有找到所要的书
printf("Sorry ! Your inquires the book was not found.\n");
}
温馨提示:答案为网友推荐,仅供参考