问题在我写了一个查询模块,我想要查询一个字符,但我就是接收不了,直接给我结束了。
//头插法
#include"Biaotou.h"
struct Deat*Creat2(){
struct Deat *head,*p;
char a;
head=(struct Deat*)malloc(LEN);
head->next=NULL;
printf("请输入链表数据,以$结束!\n");
while((a=getchar())!='$'){
getchar();
p=(struct Deat*)malloc(LEN);
p->deat=a;
p->next=head->next;
head->next=p;
}
return head;
}
void Show(struct Deat* l)
{
while(l->next!=NULL)
{
l=l->next;
putchar(l->deat);
}
printf("\n");
}
int Howlong(struct Deat* l)
{
int a = 0;
while(l->next!=NULL)
{
l=l->next;
a=a+1;
}
return a;
}
void Find(struct Deat*l){
char a;
printf("请输入你所查找的数据:");
a=getchar();
while(l->next!=NULL){
l=l->next;
if(a!=l->deat)
l=l->next;
else if(l->next==NULL)
printf("表中没有该数据!");
else {
printf("表中存在该数据!");
return;
}
}
}
int main(){
struct Deat *l;
l=Creat2();
Show(l);
printf("该链表长度为%d\n",Howlong(l));
Find(l);
return 0;
}