注册 登录
编程论坛 C++教室

创建链表问题,求指点。

e7share 发布于 2016-05-20 16:58, 3097 次点击

这是创建链表的那段函数,为什输入0停不下来?
结构体是
struct stu
{
int num;
struct stu *num;
}



struct stu *creat ()
{
    struct stu *head;
    head =NULL;
    struct stu *p1,*p2;
    p1=p2=(struct stu *)malloc(LEN) ;
    head=p1;
    scanf ("%d",&p1->num);
    while(p1->num!=0)
       {
            p2= (struct stu *)malloc(LEN);
            p1->next=p2;
            p1=p2;
            scanf ("%d",p1->num);
            }
    p1->next = NULL;
    return (head);
};
1 回复
#2
yangfrancis2016-05-20 17:57
没有定义next
1