小编Saa*_*t03的帖子

C语言中如何区分0和NULL

我正在尝试打印一些包含 integer 的整数数据0,但我想忽略包含它的数据NULL而不打印它。但我的 C 代码无法区分0NULL并将它们视为相同。

void ecrire(struct node *p) {
    if (p->data == NULL) {   'if the first node contains NULL it means list is empty'
        printf("no items!\n");
        return;
    }
    struct node *temp = p;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

当我传递第一个节点中包含值 0 的列表时,它会将其视为空列表。请问有什么解决办法吗?

c

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

标签 统计

c ×1