struct Node {
int data;
struct Node *next;
};
void insertAfterHead(struct Node **a, int x) {
struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
newNode -> data = x;
newNode -> next = *a -> next;
*a -> next = newNode;
}
int main() {
struct Node *head = NULL;
struct Node *second = NULL;
struct Node *third = NULL;
head = malloc(sizeof(struct Node));
second = malloc(sizeof(struct Node));
third = malloc(sizeof(struct Node));
head -> data = 5;
head -> next = second;
second -> data = 10;
second -> next = third;
third -> data = 15;
third -> next = NULL;
insertAfterHead(&head, 10);
return 0;
}
This is the error message I get on running the code:
error: member reference base type 'struct Node *' is not a structure or union newNode -> next = *a -> next;
error: member reference base type 'struct Node *' is not a structure or union *a -> next = newNode;
Please be as descriptive as possible as I'm a beginner to C :)