关于链表一直出现Segmentation fault错误的问题
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct students{
int s;
struct students *n;
}stu;
typedef struct _list{
struct students *head;
}List;
int add(List *ls,int number)
{
stu *p,*l;
p=(stu*)malloc(sizeof(stu));
p->n=NULL;
p->s=number;
l=ls->head;
if(l)
{
if(l->n)
{
l=l->n;
}
l->n=p;
}else{
ls->head=p;
}
}
int pin(List *ls)
{
stu *head;
head=ls->head;
while(head)
{
printf("%d\n",head->s);
head=head->n;
}
}
int main()
{
List *ls;
ls->head=NULL;;
int number=1;
while(number!=0)
{
scanf("%d",&number);
add(ls,number);
}
pin(ls);
return 0;
}
~






