title: Adding a node to the head of the linked list
body: <p>I would like to add a node in a sorted linked list based on the number. This is the struct:</p>
  
  <pre><code>struct node {
    int number;
    struct node *next;
  }
  </code></pre>
  
  <p>I am able to add to the sorted linked list correctly but can't get it to change head.</p>
  
  <p>Unfortunately I can't change the format of the function declaration so this is my function:</p>
  
  <pre><code>int create(struct node *head, int number) {
     struct node *newNode = malloc(sizeof(struct node));
     newNode-&gt;number = number;
     struct node *current = head;
  
     if (current-&gt;number == -1) {
       newNode-&gt;next = NULL;
       *head= *newNode;
       return 1;
     }
  
     //Checking if head's number is bigger than init
     if (current-&gt;number &gt; number) {
       newNode-&gt;next = current;
       *head = *newNode;
     } else {
       while(current-&gt;next != NULL &amp;&amp; (current-&gt;number &lt;= number)) {
        current = current-&gt;next;
       }
      newNode-&gt;next = current-&gt;next;
      current-&gt;next = newNode;
     }
     return 1;
  }
  </code></pre>
  
  <p>the call to the function is (Note I also can't change this):</p>
  
  <pre><code>struct node *list;
  list = initializeList();
  int num;
  num = create(list, 5);
  num = create(list, 1);
  </code></pre>
  
  <p>After the second call, the list should be 1->5. But it becomes 1->1->1->1->.....</p>
  
  <p>Edit: Code to Initialize list:</p>
  
  <pre><code>struct node * initializeList() {
    struct node *head;
    head = malloc(sizeof(struct node));
    head-&gt;next = NULL;
    head-&gt;number = -1;
    return head;
  }
  </code></pre>