c语言搜索关键字吗,c语言-以关键字搜索程序

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

typedef struct CharList_Node{

char *data;

int vaul;

struct CharList_Node *next;

}cnode;

typedef struct Int_Node{

cnode *bat;

struct Int_Node *next;

}intnode;

typedef struct IndexList_Node{

char *info;

intnode *code;

struct IndexList_Node *next;

}inode;

cnode *CreatCharList()

{

cnode *head,*hp,*tp;

char *a;

char *b="n";

int x;

a=(char*)malloc(sizeof(char));

head=(cnode*)malloc(sizeof(cnode));

head->next=NULL;

hp=head;

printf("Input the CharList,compelete by enter 'n' and number '0'.:\n");/*建立词表,输入字符串,以输入“n”+”回车”以及“0”+"回车” 结束*/

while(EOF!=(scanf("%s""%d",a,&x))&&(*a!=*b))

{

tp=(cnode*)malloc(sizeof(cnode));

strcpy(tp->data,a);

tp->vaul=x;

tp->next=hp->next;

hp->next=tp;

hp=tp;

}

return head;

}

void PrintCharList(cnode *phead)

{

cnode *p;

p=phead->next;

printf("Output the CharList Vaul:\n");

while(p)

{

printf("%s  ""%d\n",p->data,p->vaul);

p=p->next;

}

}

intnode *Compare(char *x,cnode *chead)

{

int i;

int j;

int k;

char *a;

intnode *ptr,*hp,*tp;

cnode *p;

ptr=NULL;

p=chead->next;

ptr=(intnode*)malloc(sizeof(intnode));

ptr->next=NULL;

hp=ptr;

while(p)

{ a=p->data;

i=0;

j=0;

k=0;

while((k

{

if(*(x+i)==*(a+j))

{

i++;

j++;

}

else

{

j=++k;

i=0;

}

if(i==(strlen(x)))

{

tp=(intnode*)malloc(sizeof(intnode));

tp->next=hp->next;

tp->bat=p;

hp->next=tp;

hp=tp;

}

}

p=p->next;

}

return ptr;

}

void PrintCode(intnode *inthead)

{

intnode *p;

p=inthead->next;

while(p)

{

printf("%d ""%s\n",p->bat->vaul,p->bat->data);

p=p->next;

}

}

void PrintIndexList(inode *ihead)

{

inode *ip;

intnode *intp;

ip=ihead->next;

while(ip)

{

printf("%s: ",ip->info);

intp=ip->code;

PrintCode(intp);

ip=ip->next;

printf("\n");

}

}

main()

{

cnode *pp;

intnode *pr;

inode *ihead,*hp,*tp;

char *a;

char *b="n";

ihead=(inode*)malloc(sizeof(inode));

ihead->next=NULL;

hp=ihead;

a=(char*)malloc(sizeof(char));

pp=CreatCharList();

PrintCharList(pp);

printf("Please intput index information ,complete by 'n':\n");/*输入索引关键字,以输入"n"+”回车”结束*/

while(EOF!=scanf("%s",a)&&(*a!=*b))

{

pr=Compare(a,pp);

tp=(inode*)malloc(sizeof(inode));

tp->next=hp->next;

strcpy(tp->info,a);

tp->code=pr;

hp->next=tp;

hp=tp;

printf("%s: ",tp->info);

PrintCode(pr);

printf("\n");

}

printf("Press key of 'y' output the IndexList information,overview by 'n':\n");/*输入”y”+”回车”打印索引表,输入"n"+”回车” 退出程序。*/

while(EOF!=scanf("%s",a)&&(*a!=*b))

{

PrintIndexList(ihead);

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值