这个链表操作有什么问题啊?程序怎么崩溃了?

来源:百度知道 编辑:UC知道 时间:2024/06/17 17:41:20
#include<stdio.h>
#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()
{

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++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2=NULL;
return(head);
}
void Print(struct student *head)
{
struct student *p;
p=head;
if(head!=NULL)
{
do
{
printf("%ld %5.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
}

你的这个程序我也编了的,之前我做的时候也一样不能运行。要是用tc编译系统的话要把里面的ld改成d就行了。我问老师,他说这可能是编译系统的问题。
# include <stdio.h>
# include <malloc.h>
# define LEN sizeof(struct student)
# define NULL 0
struct student
{
long num;
int score;
struct student *next;
};
int n;

struct student *creat(void)
{
struct student *head=NULL,*p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld%d",&p1->num,&p1->score);
while(p1->num!=0)
{
n++;
if(n==1)
head=p1;
else
{
p2->next=p1;
p2=p1;
}
p1=(struct student *)malloc(LEN);
scanf("%ld%d",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}

struct student *del(struct student *head , long num)
{
s