【发布时间】:2013-05-26 02:37:21
【问题描述】:
我知道其他人也发布了相同的错误,但我找不到与我类似的任何内容。我已经尝试实施一些解决方案,但无法弄清楚为什么它不起作用。
struct list_elem {
int value;
struct list *prev;
struct list *next;
};
struct list{
struct list_elem *header;
struct list_elem *footer;
};
struct list_elem *list_elem_malloc(void) {
struct list_elem *elem;
elem = malloc( sizeof(struct list_elem) );
return elem;
}
void list_init(struct list *list) {
list->header = list_elem_malloc();
list->footer = list_elem_malloc();
list->header->prev = NULL;
list->footer->next = NULL;
list->header->next = list->footer; //ERROR on this line
list->footer->prev = list->header; //same ERROR on this line
}
为什么会出错?
我在 struct list_elem 中写错了,prev 和 next 应该是 list_elems,而不是列表!!!!傻我。
【问题讨论】:
-
确实,我错了! ..谢谢绝对没有看到:)
标签: c arrays pointers error-handling