title: linked list: how to return the whole linked list after insterting
body: <p>I am trying to return the head of a linked list in the function Insert of the following program. However, it is failing with compilation error. 
  Can anyone please tell me what wrong I have done:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  struct ListNode
  {
      int data;
      struct ListNode *next;
  };
  
  
  int ListLength(struct ListNode *head)
  {
      int count = 0;
      struct ListNode *temp=head;
      while(temp!=NULL)
      {
          count++;
          temp=temp-&gt;next;
      }
      return count;
  }
  
  struct ListNode *Insert(struct ListNode *head, int value, int pos)
  {
      struct ListNode *temp,*curr;
      curr=head;
      int k=1;
      temp=(struct ListNode *)malloc(sizeof(struct ListNode));
      if(pos==1)
      {
          temp-&gt;data=value;
          if(head==NULL)
          {
              temp-&gt;next=NULL;
              head=temp;
          }
          else
          {
              temp-&gt;next=head;
              head=temp;
          }
      }
      else
      {
          while((curr!=NULL) &amp;&amp; (k&lt;pos))
          {
              k++;
              curr=curr-&gt;next;
          }
          temp-&gt;data=value;
          temp-&gt;next=curr-&gt;next;
          curr-&gt;next=temp;
  
      }
      return head;
  }
  void printList(struct ListNode *head)
  {
      struct ListNode *temp;
      temp=head;
      while(temp!=NULL)
      {
          printf("%d",temp-&gt;data);
          printf(" ");
          temp=temp-&gt;next;
      }
  }
  int main
  {
      struct ListNode *head=NULL;
      //head = NULL;
      head=Insert(head,10,1);
      //Insert(head,11,2);
      printList(head);
  
      return 0;
  }
  </code></pre>
  
  <p>I am trying to return the head of the new linked list after the insertion. I don't know where I am going wrong. Thanks in advance for the help.</p>