title: c: inserting new nodes to a singly linked list using a function
body: <p>I used a function to insert new nodes to my singly-linked list but when i print out all the values inside the nodes after insertion, i only get the value of the first node:</p>
  
  <pre><code>// Make list
  createList(head, 17);
  
  // Insert to list
  for (int x = 9; x &gt; 0; x /= 3)
  {
      if (!insertToList(head, x))
      {
          fprintf(stderr, "%s", error);
          return 1;
      }
  }
  </code></pre>
  
  <p>The function:</p>
  
  <pre><code>bool insertToList(NODE *head, int value)
  {
      NODE *node = malloc(sizeof(NODE));
      if (node == NULL)
          return false;
  
      node -&gt; number = value;
      node -&gt; next = head;
      head = node;
      return true;
  }
  </code></pre>
  
  <p><strong>-- Output: 17</strong></p>
  
  <p>When i don't use a function, everything works as expected:</p>
  
  <pre><code>// Make list
  createList(head, 17);
  
  // Insert to list
  for (int x = 9; x &gt; 0; x /= 3)
  {
      NODE *node = malloc(sizeof(NODE));
      if (node == NULL)
      {
          fprintf(stderr, "%s", error);
          return 1;
      }
  
      node -&gt; number = x;
      node -&gt; next = head;
      head = node;
  }
  </code></pre>
  
  <p><strong>-- Output: 1 3 9 17</strong></p>
  
  <p>Why ?</p>