编译错误,为什么 #include<stdio.h> #include<stdlib.h> struct student { int n;char name[

2025-04-02 10:10:59
推荐回答(2个)
回答1:

#include

struct student//////////结构体定义

{int no;
float grade;
struct student *next;};
int n;

struct student*head,*p;

struct student*creat()//////////定义输入函数
{
struct student*head;

struct student*p1,*p2;

n=0;
p1=p2=(struct student*)malloc(sizeof(struct student)); //这里要加强制转换
scanf(" %ld,%f",&p1->no,&p1->grade);

head=NULL;
while(p1->no!=0)
{n=n+1;

if(n==1)
head=p1;
else p2->next=p1;

p2=p1;
p1=(struct student*)malloc(sizeof(struct student));//这里要加强制转换
scanf(" %ld,%f",&p1->no,&p1->grade);//sco改为grade
}

p2->next=NULL;

回答2:

请检查13-14行,head为空指针!!然后把NULL赋值给p,p没有指向!