title: Sorting a linked list in an ascending way
body: <p>I am trying to write a function that inserts numbers(from the user)to nodes (1 number for each node) and then sorts them in an ascending way.
  I wrote this function:</p>
  
  <pre><code>void insertnode(struct n_node *head)
  {
      struct n_node *temp = head;
      int number;
      printf("Please insert a number to the node\n");
      scanf("%d", &amp;number);
      while (number != SENTRY)
      {
          while ((temp-&gt;next != NULL) &amp;&amp; (temp-&gt;next-&gt;num &lt; number))
          {
              temp = temp-&gt;next;
          }
          struct n_node *addNode = (struct n_node*)malloc(sizeof(struct n_node));
          addNode-&gt;num = number;
          if (temp-&gt;next == NULL &amp;&amp; number &lt; temp-&gt;num)
          {
              addNode-&gt;next = temp;
              head = addNode;
          }
          else
          {
              addNode-&gt;next = temp-&gt;next;
              temp-&gt;next = addNode;
          }
          temp = head;
          scanf("%d", &amp;number);
      }
      options();
  }
  </code></pre>
  
  <p>It compiles but right after I insert the first number is stops, gives me a break message and points on this line: </p>
  
  <pre><code>while ((temp-&gt;next != NULL) &amp;&amp; (temp-&gt;next-&gt;num &lt; number))
  </code></pre>
  
  <p>nothing appears on the error list, any help is appreciated, Thanks!</p>