主题:哪位高手指点一下为什么这个算法不能运行(加上主函数)
#define NULL 0
#include<malloc.h>
#include<stdio.h>
#define LEN sizeof(struct student)
struct student
{int age;
float score;
struct student *next;
};
struct student *Create()
{
struct student *head,*p1,*p2;
int n=0;
p1=p2=(struct student *)malloc(LEN);
printf("please input a student's agge and score:");
scanf("%3d",p1->age);
head=NULL;
while(p1->age!=0)
{n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
printf("Please input a student's age and score:");
scanf("%3d",p1->age);
}
p2->next=NULL;
return (head);
}
main()
{struct student *p,*head;
head=Create();
for(p=head->next;p->next!=NULL;p=p->next)
printf("%d",p->age);
getchar();
getchar();
getchar();
getchar();
}
#include<malloc.h>
#include<stdio.h>
#define LEN sizeof(struct student)
struct student
{int age;
float score;
struct student *next;
};
struct student *Create()
{
struct student *head,*p1,*p2;
int n=0;
p1=p2=(struct student *)malloc(LEN);
printf("please input a student's agge and score:");
scanf("%3d",p1->age);
head=NULL;
while(p1->age!=0)
{n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
printf("Please input a student's age and score:");
scanf("%3d",p1->age);
}
p2->next=NULL;
return (head);
}
main()
{struct student *p,*head;
head=Create();
for(p=head->next;p->next!=NULL;p=p->next)
printf("%d",p->age);
getchar();
getchar();
getchar();
getchar();
}