小编use*_*425的帖子

为什么在迭代C中的单链表时,NULL指针检查不起作用?

我正在尝试从堆打印.如果我遇到一个NULL指针我应该打印NULL; 否则,打印它的价值.

样本输出:

1   [2]
2   null
3   null
4   [7, 3]
5   null
6   [7]
Run Code Online (Sandbox Code Playgroud)

但是我的代码因解除引用NULL指针而不断崩溃.

这是我写的测试代码:

void printResult(IntList* intL, int nNode, int nEdge)
{
    int i;
    for (i; i <= 10; i++)
    {
        if (intRest((intL))
        {
            printf("%d", intFirst((intL)[i]));
            intRest((intL)[i]);
        }
        else
            printf(" NULL ");
    }
}

//Here is the definition of functions:
//First
int intFirst(IntList oldL)
{
    return oldL->element;
}

/** rest
 */
IntList intRest(IntList oldL)
{
    return oldL->next;
}
//=================
struct IntListNode
{
    int element;
    IntList next; …
Run Code Online (Sandbox Code Playgroud)

c null pointers loops singly-linked-list

0
推荐指数
1
解决办法
267
查看次数

标签 统计

c ×1

loops ×1

null ×1

pointers ×1

singly-linked-list ×1