title: Sorted Insertion in linked list with pointers, C program crashes
body: <p>I'm "translating" this program from a pseudo Pascal language. Recently I learned C structs and pointers features, and from the start I noticed that pointers are very annoying. So this is a recursive version of the Sorted Insertion in a Linked List algorithm, and it still gives me problems, like crashing.</p>
  
  <pre><code>typedef struct node Node;
  
  struct node
  {
    int info;
    struct node *link;
  };
  
  void ordered_insert_rec(Node *head, Node *new_node)
  {
    if(!head)
    {
      new_node-&gt;link = head;
      head = new_node;
    }
  
    if(new_node-&gt;info &lt; head-&gt;info)
    {
      new_node-&gt;link = head;
      head = new_node;
    }
    else
    {
      ordered_insert_rec(head-&gt;link, new_node);
    }
  </code></pre>
  
  <p>This is the main:</p>
  
  <pre><code>int main()
  {
    Node head;
    Node node;
    Node node2;
    Node inserting_node;
  
    head.info = 1;
    head.link = &amp;node;
  
    node.info = 3;
    node.link = &amp;node2;
  
    node2.info = 7;
  
    inserting_node.info = 5;
  
    ordered_insert_rec(&amp;head, &amp;inserting_node);
  
    Node *front = &amp;head;
    while(front)
    {
      printf("%d ", front-&gt;info);
      front = front-&gt;link;
      if(!front)
      {
        exit(1);
      }
    }
  }
  </code></pre>
  
  <p>Maybe I'm doing something wrong with the list printing at the end of the algorithm, is it? In the prompt the output is "1 3 7" but the program crashes after a while. It must be "1 3 5 7", by this way I noticed up that the procedure "ordered_insert_rec" doesn't work correctly.</p>
  
  <p>Thanks for the help. :)</p>