C链表 哪儿错了 高手指教

来源:百度知道 编辑:UC知道 时间:2024/07/04 11:51:10
#include <malloc.h>
#define NULL 0
#define LEN sizeof (struct student)
struct student
{ long num ;
float score ;
struct student * next ;
};
int n ;
struct student * creat (void)
{
struct student * head ;
struct student *p1 , *p2;
n=0 ;
p1=p2=(struct student * )malloc(LEN);
scanf("%ld ,%f",&p1.num ,&p1.score);
head=NULL ;
while (p1.num!=0)
{
n=n+1 ;
if(n==1) head=p1 ;
else p2.next=p1 ;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%d,%f",p1.num,p1.score);
}
p2.next=NULL;
return(head);
}
void ptint(struct student * head)
{
struct student *p;
printf("\n Now ,these %d records are : \n",n);
p=head ;
if (head!=NULL)
do
{printf( " %ld %5.1f\n",p.score);
p=p.next;
}
while(p!=NULL);
}
struct st

首先要加#include<stdio.h>因为你用了scanf,printf等函数,还有creat函数的返回值应该是struct student * head 类型的,而不是void 空类型的。还有,因为已经定义了指针类型的p1,p2。所以不能&p1.num ,&p1.score。应该是&p1->num,&p1->score……其他的问题还在看中……

帮你大致看了下,问题有点多,主要是小错误

你仔细看看你的语句,肯定能发现很多错误

自己慢慢修改吧,对你有帮助