C中的段错误,求指导
publish函数中,LOT是结构体,我创建了一个结构体指针new_n,并且用malloc赋予它地址空间,然后我用insert_tail_lot函数将new_n加入链表,并且用length_lot函数求出链表长度,并且赋给结构体中的issue.但是程序运行出现段错误,请问是哪里错了?void publish(LOT *lot_head)
{
LOT *new_n = NULL;
new_n = malloc(sizeof(LOT));
insert_tail_lot(lot_head,new_n);
new_n->issue = length_lot(lot_head);
printf("第%d期\n",new_n->issue);
}
int insert_tail_lot(LOT *lot_head,LOT *new_n)
{
if(new_n == NULL){
return 1;
}
find_tail_lot(lot_head)->next = new_n;
new_n->next = NULL;
return 0;
}
LOT *find_tail_lot(LOT *lot_head)
{
LOT *tail = NULL;
tail = lot_head;
while(tail->next != NULL)
tail = tail->next;
return tail;
}
int length_lot(LOT *lot_head)
{
int len=0;
LOT *cur=NULL;
cur=lot_head->next;
while(cur != NULL){
len++;
cur = cur->next;
}
return len;
}