大佬可以帮忙找下问题吗...创建单向链表总是出问题
#include <stdio.h>
#include <stdlib.h>
struct student
{
int num;
struct student *next;
};
struct student *creat(int n){
struct student *head,*pnew,*ptail;
int i;
pnew=(struct student *)malloc(sizeof(struct student));
scanf("%d",&pnew->num);
head=ptail=pnew;
for(i=1;i<n;i++){
pnew=(struct student *)malloc(sizeof(struct student));
scanf("%d",&pnew->num);
ptail->next=pnew;
ptail=pnew;
}
ptail->next=NULL;
return head;
};
void print(struct student *head){
struct student *p=head;
while(p!=NULL){
printf("%d",p->num);
p=p->next;
}
}
int main()
{
int n,i;
struct student *head;
scanf("%d",&n);
creat(n);
print(head);
return 0;
}