我无法将新列表插入到我的结构中。有人可以帮帮我吗?谢谢!:) 这是我的代码和错误:
编译后报错:
27:9:错误:从类型“node_t * {aka struct _node_t *}”分配给类型“node_t {aka struct _node_t}”时类型不兼容
代码:
typedef struct _node_t {
double d;
struct _node_t *next;
} node_t;
void print_list (node_t *l) {
node_t *curr = l;
printf("[");
while (curr != NULL) {
if (l != curr) printf (",");
printf("%4.1f",curr->d);
curr = curr->next;
}
printf("]\n");
}
node_t *insert (node_t *l, double d) {
node_t *new_node;
new_node = (node_t *) malloc (sizeof(node_t));
if (new_node == NULL) {
printf("insert: error: no space left\n");
return l;
}
new_node->d = d;
new_node->next = l;
return new_node;
}
int main (void)
{
node_t n1;
print_list(&n1);
n1=insert(n1,10);
}