I have made a simple linkedlist implementation and I am getting this error on when I am running the code at Insert() function call in Main(), I dont understand Why so.

#include<stdio.h>
#include<stdlib.h>
  struct Node
  {
     int data;
     struct Node *next;
  };
  struct Node* head;
 int main(){
    head=NULL;
    Insert(1,2);
    Insert(2,1);
    Insert(3,1);
    Insert(4,1);        
 } 
 void Print(){
    struct Node* temp;
    temp=head;
    while(temp!=NULL){
        printf("%d ",tenp->data);
        temp=temp->next;
     }
    printf("\n");
 }
 Node* Insert(Node *head,int data)
 {
    Node *node = new Node();
    node->data = data;              // ASSIGNING VALUES TO NEW NODE
    node->next = NULL;                 // ALSO AS TO ACT AS THE TAIL NODE ADDING THE null VALUE AT THE NEXT POINTER 
    if(head == NULL)               // CASE: WHEN LIST IS EMPTY
        return node;
    Node *temp = head;       // dereferencing value for TEMP,  assignning it the HEAD values, HEAD is the current tail node
    while(temp->next != NULL)         // Traversing till 1 before
        temp = temp->next;             
    temp->next = node;                      // making the last move, assigning the LINK to new node.  
    return head;                                // returinng the funn call with VALUE
}
2

There are 2 best solutions below

0
On
 Insert(1,2)//this won't work as insert() 
            //expects node* type and not an integer as first argument.

You should pass the pointer to head instead of the value.

0
On

You are passing 1,2,3 and 4 into a Node* argument. You have to pass the actual head node and assign the result,

head = Insert( head, value );

Thats how you made the function to be used.