单链表按值查找总是出错【求助】·
#include<stdio.h>#include<stdlib.h>
typedef struct node
{
char data;
struct node *next;
}linklist;
linklist *creat(linklist *head)
{ char ch;
linklist *p,*s;
head=(linklist*)malloc(sizeof(linklist));
p=head;
ch=getchar();
while(ch!='$')
{
s=(linklist*)malloc(sizeof(linklist));//(linklist*)malloc(sizeof(linklist));
s->data=ch;
p->next=s;
p=s;
ch=getchar(); }
p->next=NULL;
return head;
}
linklist *locate(linklist *abc)
{
char a;
linklist *p;
printf("请输入你要查找的值:\n");
scanf("%c",&a);
p=abc->next;
while(p!=NULL)//查找值的操作
if(p->data!=a)
p=p->next;
else
break;
return p;
}
int main()
{
linklist *head;
linklist *shu,*shuzi;
shu=creat(head);
shuzi=locate(shu);
printf("%c",shuzi->data);
return 0;
}