C语言问题
#include<stdio.h>#defineNULL0#defineTYPEstructstu#defineLENsizeof(structstu)structstu...
#include<stdio.h>
#define NULL 0
#define TYPE struct stu
#define LEN sizeof (struct stu)
struct stu{
int num;
int age;
struct stu *next;
};
TYPE *creat(int n){
struct stu *head,*pf,*pb;
int i;
for(i=0;i<n;i++){
pb=(TYPE*) malloc(LEN);
printf("input Number and Age\n");
scanf("%d%d",&pb->num,&pb->age);
if(i==0) pf=head=pb;
else pf->next=pb;
pb->next=NULL;
pf=pb;
}
return(head);
}
运行出错,要怎么改 展开
#define NULL 0
#define TYPE struct stu
#define LEN sizeof (struct stu)
struct stu{
int num;
int age;
struct stu *next;
};
TYPE *creat(int n){
struct stu *head,*pf,*pb;
int i;
for(i=0;i<n;i++){
pb=(TYPE*) malloc(LEN);
printf("input Number and Age\n");
scanf("%d%d",&pb->num,&pb->age);
if(i==0) pf=head=pb;
else pf->next=pb;
pb->next=NULL;
pf=pb;
}
return(head);
}
运行出错,要怎么改 展开
1个回答
展开全部
#include<stdio.h>
#include<malloc.h> //添加头文件
#define NULL 0
#define TYPE struct stu
#define LEN sizeof (struct stu)
struct stu{
int num;
int age;
struct stu *next;
};
TYPE *creat(int n)
{
struct stu *head,*pf,*pb;
int i;
for(i=0;i<n;i++){
pb=(TYPE*) malloc(LEN);
毕宏埋printf("input Number 手蚂and Age\n");
scanf("%d%d",&pb->num,&pb->age);
绝团 if(i==0) pf=head=pb;
else pf->next=pb;
pb->next=NULL;
pf=pb;
}
return(head);
}
void main()
{
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询