求C语言高手~~~

2025-12-16 10:58:34
推荐回答(3个)
回答1:

#include
#include
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student *next;
};

struct student *creat(void)
{
struct student*head;
struct student*p1,*p2;
int n;
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;
return(head);
}
void main()
{
creat();
}

1去掉#define NUll 0
2去掉全局变量
3去掉没用到的变量

回答2:

代码没问题
你在scanf("%ld,%f",&p1->num,&p1->score); 前面加上p1->score=0.0就可以了。
或者换一个编译器。
你用的是turbo2.0这种?

回答3:

程序没有发现问题,请检查你的输入格式。