代码中的分段错误

时间:2013-02-25 13:54:41

标签: c

我不断得到分段错误,但我不知道为什么,我弄清楚我的分段错误在哪里,但不知道如何解决它。

struct node {
        int line;
        int count;
        char* word;
        struct node* next;
};

struct node* nodeGetPreviousNode (struct node* head, struct node* node)
{
        //return the previous node given the node
        while(((head) != NULL) ||((head)->next != node))
        {
                (head) = (head)->next;
        }
        return (head);
}

1 个答案:

答案 0 :(得分:8)

while(((head) != NULL) ||((head)->next != node))

将评估(head)->next != node,在headhead

时解除引用NULL

您的意思是使用&&吗?