C语言实现单向链表错误输出问题

C语言实现单向链表错误输出问题
#include
#include
struct student{
    int num;
    char name[10];
    int gra;
    struct student* next;
};
struct student *create();
int main(){
    int n;
    struct student *head,*p;
    head=create();
    scanf("%d",&n);
    for(p=head->next;p!=NULL;p=p->next){
        if(p->gra>=n) printf("%d %s %d\n",p->num,p->name,p->gra);
    }
    return 0;
}
struct student *create(){
    struct student *head,*node,*end;
    head=(struct student*)malloc(sizeof(struct student));
    end=head;
//    head->next=end;
    while(1){
        node=(struct student*)malloc(sizeof(struct student));
        int num;
        scanf("%d",&num);
        if(num==0){
            break;
        }
        node->num=num;
        scanf("%s%d",node->name,&node->gra);
        end->next=node;
        end=node;
    }
    end->next=NULL;
    return head;
}


img


这个代码可以正常输出
但是我把end=head删去只用head->next=end就输出错误?

img


不理解为什么会这样
希望 前 辈 不吝赐教

因为如果删除了end=head之后end等于没有分配内存,是野指针。