请高手指点:以字符串为数据的单链表操作
#include <stdio.h>#include <string.h>
#define null 0
typedef struct node{
char *data;
struct node *next;
}linkstrnode;
typedef linkstrnode *linkstring;
main()
{
linkstring head;
char *t;
printf("\n please input the node of the linklist : ");
printf("\n nodes data is string , and end of # \n");
creatlinkstr(&head);
printf("\n the source linklist is : \n");
printing(head);
printf("\n please input search string : ");
gets(t);
deletet(&head,t);
printf("\n the final linklist is : \n");
printing(head);
}
creatlinkstr(linkstring head){
char *t;
linkstrnode *p;
head=(linkstrnode *)malloc(sizeof(linkstrnode));
head->next=null;
printf("\n please input the node data(string),end of #");
gets(t);
while (strcmp(t,"#")!=0){
p=head;
while ((p->next)&&(strcmp(t,p->next->data))) p=p->next;
if (p->next)
printf("\n string %s existed",t);
else {
p->next=(linkstrnode *)malloc(sizeof(linkstrnode));
p=p->next;
strcay(p->data,t);
p->next=null;
}
printf("\n please input the node data(string),end of # ");
gets(t);
}
}
printing(linkstring head){
linkstrnode *p;
p=head->next;
while(p){
puts(p->data);
p=p->next;
}
}
deletet(linkstring head,char *t){
linkstrnode *p,*s;
p=head;
while ((p->next)&&(strcmp(p->next->data,t)))
p=p->next;
if (p->next){
s=p->next;
p->next=s->next;
free(s);
printf("\n delete successful!");
}
else printf("\n deletet failure!");
}
本程序编译可以通过,但在gets(t)一直会有警告?
请高手指点迷津,跪谢!!!