怎么在这个代码里加入索引表啊
我想让大家帮忙看看,能不能在我这个程序里加个索引表,怎么加呢?这个我还不会,是要用来建立关键词索引的,要输入关键词就可以找到书,还有那个怎么把录入的书目导入到硬盘啊,不然再开程序前面输入的都搜不到了
程序代码:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct bookaddr //定义书目结构
{
char bookname[30];//书名
char author[20]; //作者
char publisher[40]; //出版社
char publishtime[20]; //出版时间
char loginnum[10]; //登录号
struct bookaddr *next; //链表指针域
}record;
struct bookaddr *head,*start; //新建链表
struct bookaddr *last;
int menu_select();
void enter();
void deleted();
void search();
void main() //.....................................................
{
char s[80],choice;
struct bookaddr *info;
start=last=NULL;
while(1)
{
switch(menu_select())
{
case 1:enter();
break;
case 2:deleted();
break;
case 3:search();
break;
case 4:exit(0);
}
}
}
int menu_select() //............................
{
char s[80];
int c;
printf("-------------------------------欢迎使用图书检索系统-----------------------------\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~请选择相应的功能选项~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n");
printf("1__请输入新书\n");
printf("2__删除记录\n");
printf("3__搜索\n");
printf("4__退出\n");
do
{
printf("\n 请输入您的选择:");
gets(s);
c=atoi(s);
}while(c<1||c>4);
return(c);
}
struct bookaddr* des_store(struct bookaddr *i,struct bookaddr *top) //............................................................
{
if(!last)
{
last=i;
return(i);
}
else
{
top->next=i;
i->next=NULL;
last=i;
return(i);
}
}
void enter() //....................................................................
{
struct bookaddr *info;
void inputs(char *,char *,int );
int n;
for(n=0;;n++)
{
printf("输入 0结束\n");
info=(struct bookaddr *)malloc(sizeof(record)); //分配内存给info
if(info==NULL)
{
printf("\n 内存不足");
return;
}
inputs("输入书名:",info->bookname,30);
if(info->bookname[0]=='0') //结束书本录入
break;
else
{
inputs("输入作者:",info->author,40);
inputs("输入出版社:",info->publisher,20);
inputs("输入出版时间:",info->publishtime,3);
inputs("输入书号:",info->loginnum,11);
start=des_store(info,start);
if(n==0)
head=start;
}
}
}
void inputs(char *p1,char* s,int count) //....................................................................
{
char p[40];
do
{
printf("%s",p1);
gets(p);
if (strlen(p)>count)
printf("\n too long\n"); //录入数目不大于书库容量
}while(strlen(p)>count);
strcpy(s,p); //把字符指针p指针所指向的字符串复制到s指向的地方
}
void display(struct bookaddr *info) //输出函数.....................................................................
{
printf("书名:%s\n",info->bookname);
printf("作者:%s\n",info->author);
printf("出版社:%s\n",info->publisher);
printf("出版时间:%s\n",info->publishtime);
printf("登录号:%s\n",info->loginnum);
printf("\n\n");
}
struct bookaddr *find(char *bookname) //..........................................................................
{
struct bookaddr *info; //定义结构体指针变量
info=head; //把头指针赋给info
while(info) //info的值不为NULL时循环
{
if(!strcmp(bookname,info->bookname)) //判断参数的 bookname与链表中的书本名称是否相等
return(info); //相等就返回这个节点的指针
else
info=info->next; //否则info指向下一个节点
}
return(info); //找不到的情况下返回NULL
}
void search() //..................................................................................................
{
char bookname[40];
struct bookaddr *info;
printf("请输入书名:");
gets(bookname);
if((info=find(bookname))==NULL)//判断是否找到输入的书
printf("查无此书\n");
else
display(info);
}
void deleted()//...............................................................................................
{
char s[80];
struct bookaddr*p1,*p2,*info;
printf("请输入书名:");
gets(s);
info=find(s);
if(info!=NULL)
{
if (head==info)
{
head=info->next; //指向下一节点
printf("删除:%s\n",info->bookname);
free(info); //释放节点内存
}
else
{
p1=head->next;
while(info!=p1)
{
p2=p1;
p1=p1->next;
}
p2->next=p1->next;
printf("删除:%s\n",info->bookname);
free(info);
}
}
else
printf("%s 我找不到!!\n",info->bookname);
}这个要怎么加入关键词索引啊,还有怎么把输入的导入到硬盘,之后再打开时可以直接搜索,我这个再运行时就搜不到之前运行时输入的了。。。。。。忘帮忙啊,今天要搞好







来人啊。。。。。。。锕。。。。。啊。。。。。。。。
·························这么多人看都没一个懂的么。。。。

