Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么这段代码在链表尾部插入节点会导致分段错误_C_Data Structures_Linked List_Clang - Fatal编程技术网

C 为什么这段代码在链表尾部插入节点会导致分段错误

C 为什么这段代码在链表尾部插入节点会导致分段错误,c,data-structures,linked-list,clang,C,Data Structures,Linked List,Clang,我试图实现linkedlist函数在列表末尾添加节点,但它几乎在每一行中都会触发分段错误 SinglyLinkedListNode*插入节点尾部(SinglyLinkedListNode*头,int数据){ 这可能导致seg故障: while(current->next != NULL) /* if current is NULL dereferencing it will cause segfault. */ 提示:仔细考虑你的“0元素列表”案例。特别是,分配给head实际上没有任

我试图实现linkedlist函数在列表末尾添加节点,但它几乎在每一行中都会触发分段错误

SinglyLinkedListNode*插入节点尾部(SinglyLinkedListNode*头,int数据){


这可能导致seg故障:

while(current->next != NULL)  /* if current is NULL 
dereferencing it will cause segfault. */

提示:仔细考虑你的“0元素列表”案例。特别是,分配给
head
实际上没有任何作用…请记住,C中的参数是按值传递的。您可以使用调试器或valgrind或address sanitizer之类的工具来调试segfaults。这可能会有帮助。您可以显示完整的程序吗?我怀疑问题部分与列表的状态有关调用此函数时。请发布一个包含哪些头文件、结构定义
SinglyLinkedListNode
以及其他关键的、缺失的详细信息,包括包含发布的代码片段的完整函数
while(current->next != NULL)  /* if current is NULL 
dereferencing it will cause segfault. */