关于建立动态链表的问题
题目是建立一个动态链表,请各位大侠帮我看一下哪里出错了,我看了N久都没有找出错误#include<iostream.h>
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int num;
int score;
struct student *next;
};
int n;
struct student *cread(void)
{
struct student *head,*p1,*p2;
n=0;
head=NULL;
while(p1->num!=0)
{
p1=(struct student*)malloc(LEN);
n++;
cout<<"please iput the numble and score:";
cin>>p1->num;
cin>>p1->score;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
}
p1->next=NULL;
return(head);
}
int main()
{
struct student *p;
p=cread();
return 0;
}