如何摆脱NULL分段错误?

use*_*891 1 c pointers segmentation-fault

我在C中创建一个链表程序,我继续得到分段错误.我已经将问题缩小到几行代码,我相信它与检查NULL有关.我怎样才能解决这个问题?这是代码:

typedef struct node
{
  int contents;
  struct node *nextNode;
}  Node;



deleteNode(Node *currentNode)
{

  while((currentNode->contents) != NULL)
  {
    //.....Do Stuff.....
    currentNode = currentNode->nextNode;
  }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

fli*_*ght 7

尝试检查以确保它currentNode不在NULL开头deleteNode().即

deleteNode(Node *currentNode)
{
    if (currentNode == NULL) return;
    // ...
    // ...
}
Run Code Online (Sandbox Code Playgroud)