怎么使用结构体数组(C语言)

我要做用图书管理系统 要把每一个书的 书名 使用情况 和 简要内容放在结构数组中 求怎么做

代码仅供参考:

#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");
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-30
先定义一个结构体 假设说是
struct a
{
……;
};
然后就
struct a[NUM];
就可以和平常一样用了:
比如说a[1].***之类的。
第2个回答  2010-11-02
先定义结构体
struct book
{
char bookname[10];
int useyn;/*可描述两种状态“借出”或“未借出”*/
char neirong[100];
};
再用book定义结构体类型的数据,如:struct book book;
第3个回答  2010-10-30
用电脑
相似回答