【发布时间】:2017-04-10 23:09:17
【问题描述】:
我想编写一个列表中包含列表的程序。 于是就有了 list.h 文件:
typedef struct node {
void *ptr;
struct node *next;
struct node *prev;
} NODE;
typedef struct list {
struct node *head;
struct node *tail;
int size;
char name[MAX_SIZE_NAME];
} LIST;
起初我有一个列表,例如list_。 现在我分配了 5 个元素。
我想在每个节点中分配一个新列表。 我试过这段代码:
if (list_->head->next == list_->tail) {
list_ins_next(list_);
ptr = list_->tail->prev;
ptr->ptr = malloc(sizeof(LIST));
ptr->ptr->head = malloc(sizeof(NODE));
对不起,我没有这么多的编程经验,但如果你能帮助我,那就太好了
错误是:取消引用'void *'指针
【问题讨论】:
-
node::ptr代表什么?它是否意味着始终指向包含struct list或任意数据存储? -
另外,如果你使用
void*,你可能做错了什么(因为你放弃了类型安全)。
标签: c linked-list void-pointers