求大佬看看链表哪有问题,在线等急
#include<stdio.h>
#include<stdlib.h>
struct stu
{
int num;
struct stu *next;
};
struct stu *creat()
{
struct stu *head;
struct stu *p,*q;
q=p=(struct stu*)malloc(sizeof(struct stu));
head=NULL;
for(; q->num!=10;)
{
printf("输入\n");
scanf("%d",&p->num);
if(head==NULL)
{
head=p;
}
else
{
q->next=p;
q=p;
}
q->next=NULL;
}
return head;
}
void main()
{
struct stu *u;
u=creat();
for(; u!=NULL; u=u->next)
{
printf("%d",u->num);
}
}