C语言~~关于链表~~运行出错

来源:百度知道 编辑:UC知道 时间:2024/05/14 03:41:11
#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;
void main()
{
struct student *creat(void);
struct student *head;
printf("input records:\n");
head=creat();
putchar ('\n');
}

struct student *creat(void)
{
struct student *p1,*p2;
struct student *head;
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 ("%ld%f",&p1->num,&p1->score);
}
p2->next=NULL;
free(p1);
return (head);
}

运行时出现
Dedbug Error
P

浮点库没加载,一个老Bug。

void main()
{
struct student *creat(void);
struct student *head;
float nop=0.1;
sqrt(nop);//做点无意义的浮点运算即可
printf("input records:\n");
head=creat();
putchar ('\n');
}