C语言 这个程序哪错了 啊

来源:百度知道 编辑:UC知道 时间:2024/06/01 17:30:01
#include<stdio.h>
#include<malloc.h>
#define null 0
#define len sizeof(struct student)

void main()
{

struct student * build(void);

build();
printf("ddd" ) ;
}

struct student * build(void)
{
struct student
{
long num;
int m;
struct student * next;
};
struct student *head;
struct student *p1,*p2;
int n;
n=0;
p1=p2=(struct student *)malloc(len);
head=null;
while(p1->num!=0)
{n=n+1;
if(n==1) head=p1;
else p1->next=p2;
p1=p2;
p2=(struct student*)malloc(len);
scanf("%ld,%d",&p1->num,&p1->m);
}
p2->next=null;
return(head) ;

}

//给你个我测试通过的代码,应改满足你的要求;
//你的问题蛮多的,参考下我的看看吧

#include<stdio.h>
#include<malloc.h>
#define null 0
#define len sizeof(struct student)

struct student
{
long num;
int m;
struct student * next;
};

struct student * build(void)
{

struct student *head;
struct student *p1,*p2;
int n;
n=0;
p1=p2=(struct student *)malloc(len);
head=p1;
scanf("%ld,%d",&(p1->num),&(p1->m));
while(p1->num!=0)
{
p2=(struct student*)malloc(len);
p1->next=p2;
p1=p2;
scanf("%ld,%d",&(p1->num),&(p1->m));
}
p2->next=null;
return(head) ;
}

int main()
{
build();
printf("ddd" ) ;

return 0;
}

struct student 的定义要放在全局空间
不要放在函数体内