c - Using structures in a linked list -
c - Using structures in a linked list -
i trying create append_node method add together node linked list created. node construction defined below:
typedef struct node{ struct node next = null; int id; } node; however, when compiling method below, next error: 'node' has no fellow member named 'id' 'node' has no fellow member named 'next'
void append_node(node *sent,int val){ node *other_node = (struct node *)malloc(1*sizeof(struct node)); other_node->id = val; node n = *sent; while (n.next != null){ n = n.next; } n.next = other_node; } why error occurring?
edit:
i have next error
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token on first line of node definition
there numerous errors in code. here right version
typedef struct nodetag { struct nodetag* next; int id; } node; void append_node(node* sent,int val) { node* other_node = (node*)malloc(sizeof(node)); other_node->id = val; other_node->next = 0; node* n = sent; while (n->next != 0) { n = n->next; } n->next = other_node; } c
Comments
Post a Comment