求大佬帮助,怎么解决啊!!!用的C语言做的动态链表!分配头节点空间时出错
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
typedef struct node NODE;
NODE* creat(){
node *head,*p,*q;
int num;
head = malloc(sizeof(NODE));
p = head;
while(1){
printf("输入一个总分:");
scanf("%d",&num);
if(num < 0){
break;
}
q = malloc(sizeof(NODE));
q->data = num;
p->next = q;
p = q;
p->next = NULL;
return head;
}
}
int main(){
NODE* h;
h=creat();
printf("head:%p\n",h);
return 0;
}