I am trying to create an append_node method to add a node to a linked list I created. My Node structure is defined below:
typedef struct Node{
struct Node next = NULL;
int id;
} Node;
However, when compiling with the method below, I get the following error: 'Node' has no member named 'id' 'Node' has no 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 is this error occurring?
EDIT:
I also have the following error
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
on the first line of the Node definition
structcan not hold an instance of the same type as itself.struct Node *next = NULL;(i.e. missing*).nshould be a pointer