试图测试以下功能后,我已经确定注释掉行给出了一个赛格故障,当我尝试运行该程序:如何更改struct中指针指向的值c?
uint8_t ll_push_front(struct List *list, int value){
if (list == NULL)
return 1;
struct ListEntry *node = (struct ListEntry *) malloc (sizeof(struct ListEntry));
if (node == NULL) exit (1);
if (list->head_ == NULL || list->tail_ == NULL || list->size_ == 0) {
list->head_ = node;
list->tail_ = node;
node->prev_ = NULL;
node->next_ = NULL;
// =====>> *(node_->val_) = value;
++(list->size_);
return 0;
}
list->head_->prev_ = node;
node->next_ = list->head_;
node->prev_ = NULL;
*(node->val_) = value;
list->head_ = node;
++(list->size_);
return 0;
}
什么是错的做*(node_->val_) = value
以及究竟应该如何正确申报?
这里的结构:
struct ListEntry {
struct ListEntry * next_; // The next item in the linked list
struct ListEntry * prev_; // The next item in the linked list
int * val_; // The value for this entry
};
/* Lists consist of a chain of list entries linked between head and tail */
struct List {
struct ListEntry * head_; // Pointer to the front/head of the list
struct ListEntry * tail_; // Pointer to the end/tail of the list
unsigned size_; // The size of the list
};
这是我用来初始化列表:
void ll_init(struct List **list) {
*list = (struct List *) malloc (sizeof(struct List));
if (list == NULL) exit (1);
(*list)->head_ = 0;
(*list)->tail_ = 0;
(*list)->size_ = 0;
}
如何'node_'声明,它在哪儿设置? – lurker
需要知道你是如何定义结构的 –
如果val_是一个int,那么你应该做'node _-> val_ = value;' – UncleO