【发布时间】:2014-01-09 18:11:04
【问题描述】:
我想创建一个链表,初始化它并在开头添加一个新节点。 但是我有这个问题:
//// 错误:在不是结构或联合的东西中请求成员“值” ////
t_bool list_add_elem_at_front(t_list *front_ptr, double elem)
{
if (front_ptr == NULL)
{
front_ptr = malloc(sizeof(*front_ptr));
front_ptr->value = elem;
front_ptr->next = NULL;
}
printf("%f\n", front_ptr->value);
return (TRUE);
}
我确定结构是 malloc,但我真的不明白为什么它在结构上找不到“值”和“*next”
int main(void)
{
int i = 2.1;
t_list list_head = NULL;
list_add_elem_at_front(&list_head, i);
}
还有头文件
typedef struct s_node
{
double value;
struct s_node *next;
} t_node;
typedef t_node *t_list;
【问题讨论】: