大家帮我看看这个代码为什么输出不了

大家帮我看看这个代码为什么输出不了

问题描述:

```c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
int main()
{
int n;
scanf("%d",&n);
struct node *head,*p,*q,*t;
head=NULL;
int i;
int a;
for(i=1;i<=n;i++){
scanf("%d",&a);
p=(struct node *)malloc(sizeof(struct node));
p->data=a;
p->next=NULL;
if(head==NULL){
p=head;
}else{
q->next=p;
}
q=p;
}
t=head;
while(t!=NULL){
printf("%d ",t->data);
t=t->next;
}
return 0;
}

```)

if(head==NULL){
p=head;
这里改为head=p;