【发布时间】:2016-10-21 04:55:25
【问题描述】:
代码中有没有遗漏的部分?
我正在创建一个非空链接 list 并显示链表的内容。我哪里弄错了?
#include <stdbool.h>
#include <stdlib.h>
struct node_int
{
void *data;
node next;
};
typedef struct node_int *node;
typedef struct list_int { node first; } *list;
void init_list(list *lp, void *o)
{
*lp = (list) malloc(sizeof(struct list_int));
(*lp)->first = NULL;
(*lp)->first->data = o;
(*lp)->first->next = NULL;
}
void print(list ell, void (*print_data)(void *d))
{
list c;
c = ell;
while (c!NULL)
{
print_data(c->data);
c = ell;
}
}
【问题讨论】:
-
(*lp)->first = NULL; (*lp)->first->data = o;:NULL->data = o;!! -
print_data(c->data); c = ell;不更新c。 -
能否请您发布可编译的代码,或者更好地说明整个程序以及它在哪里出现问题,以便我们知道在哪里寻找问题?
标签: c struct linked-list