I am trying to add nodes right after the *add pointer in my linked list my struct and code is as follows, but shows an error in (*add)->next = new_node:
typedef struct {
int data;
struct node* next;
}node;
void create_node(node **add,int dat)
{
if((*add) == NULL)
{
(*add) = (node*)malloc(sizeof(node));
(*add)->data = dat;
(*add)->next = NULL;
}
else
{
node *new_node = (node*)malloc(sizeof(node));
new_node->data = dat;
new_node->next = (*add)->next;
(*add)->next = new_node; //assignment to incompatible pointer type error
}
}