Why am I getting this warnings in my insertNode()
:
warning: assignment from incompatible pointer type [enabled by default]|
in this line:
head->next = newNode; //point head's next to the newNode
and
warning: initialization from incompatible pointer type [enabled by default]|
in this line:
Node *current = head->next;
In my main()
function I have also this warning:
warning: passing argument 1 of 'insertNode' from incompatible pointer type [enabled by default]|
in this line:
insertNode(&head, num);
I have a bunch of others similar to these warnings in my code. How can I fix them?
typedef struct NodeStruct{
int data;
struct Node *next;
}Node;
void insertNode(Node *head, int data){
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->data = data;
if(head->next == NULL){
head->next = newNode;
newNode->next = NULL;
}
else{
Node *current = head->next;
while(current != NULL && current->data < data){
current = current->next;
}
newNode->next = current->next;
current->next = newNode;
}
}
int main(int argc, char *argv[])
{
Node *head = malloc(sizeof(NodeStruct));
head->next = null;
insert(head, 22);
insert(head, 55);
insert(head, 44);
insert(head, 2);
insert(head, 2112);
insert(head, 3);
printList(head);
return 0;
}