链表的查找操作问题
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NULL 0
#define LEN sizeof(struct student)
//定义节点结构
struct student
{
char no[7];
int score;
struct student *next;
};
//create()函数:创建一个具有头结点的单链表
//返回值:返回单链表的头指针
struct student *create(void)
{
struct student *head=NULL,*p1,*p2=NULL;
int count=0;
while(1)
{
p1=(struct student *)malloc(LEN);
printf("编号%d:",count+1);
scanf("%6s",p1->no);
if(strcmp(p1->no,"000000")==0)
{
free(p1);
break;
}
printf("成绩%d:",count+1);
scanf("%d",&p1->score);
count++;
p1->next=NULL;
if(count==1)
head=p1;
else
p2->next=p1;
p2=p1;
}
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("学生们的成绩是:\n");
p=head;
while(p!=NULL)
{
printf("%s,%d\n",p->no,p->score);
p=p->next;
}
}
struct student *FindNode(struct student *head,int i)//依节点查找
{
struct student *p=head;
int j=1;
while(p->next!=NULL&&i>j)
{
p=p->next;
j++;
}
if(i==j)
return p;
else
return NULL;
}
struct student *Find(struct student *head,char *key)//依值查找
{
struct student *p=head;
while(p!=NULL)
if(strcmp(p->no,key)!=0)
p=p->next;
else
break;
return p;
}
void main()
{
int *ch;
struct student *pt;
pt=create();
print(pt);
scanf("%s",ch);
pt=Find(pt,ch);
printf("%s,%d\n",pt->no,pt->score);
}
//求解 ,运行的 时候,出现了错误
//是什么原因呢










