初始化循环链表失败不知道问题何在

想初始化一个循环链表,但不知道问题出在哪里
#include <stdio.h>
#include <stdlib.h>

struct stu{
int data;
struct stu *next;

};
void setup(struct stu **pNode);
int main()
{
//printf("%d",Large);
struct stu *p,*h;
h=NULL;
setup(&h);
for(p=h;p->next!=h;p=p->next){

    printf("%d\t",p->data);
}
return 0;

}
void setup(struct stu **pNode)
{
struct stu *r;
struct stu *temp;
int i;
printf("please in put the number \n");
printf("if i='0' quit\n");

 while(1){
    scanf("%d",&i);
    
    if(0==i) return ;
    if((*pNode)==NULL){
        (*pNode)->data=i;
        (*pNode)->next=*pNode;

    }
    else {
        for(r=(*pNode);r->next!=(*pNode);r=r->next)
            ;//利用循环本身
            temp=(struct stu*)malloc(sizeof(struct stu));
            temp->data=i;
           temp->next=(*pNode);
           r->next=temp;



    }






 }

}

if(( * pNode)==NULL){
( * pNode)->data=i;
( * pNode)->next= * pNode;

明知道 * pNode为NULL,怎么还去操作data和next呢???
要增加指针的空间动态分配

if((*pNode)==NULL){
        (*pNode) = (struct stu*)malloc(sizeof(struct stu));
        (*pNode)->data=i;
        (*pNode)->next=*pNode;
 
    }


您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632