我正在尝试在链表中添加节点,传递指针的指针,访问成员 (*list) -> next 给出了分段错误。谁能指出错误,提前谢谢。代码是
void initializeList (node ** head, int data)
{
*head = malloc (sizeof (node));
(*head)-> member = data;
(*head)-> next = NULL;
}
void addNode(node ** list, int data)
{
node * newNode = NULL;
newNode = malloc (sizeof (node));
while (*list->next!= NULL)
{
*list= (*list) -> next;
}
newNode -> member = data;
newNode -> next = NULL;
(*list) -> next = newNode;
}
void main ()
{
node * head = NULL;
initializeList (&head, 5);
addNode(&head, 6);
}