Linked list sorted in C
<p>In the program below I try to sort a list of people in ascending order. However, I get a segmentation fault and I don't know how to change the program in order to give the expected result. Any suggestions?</p>

<pre><code> #include &lt;stdio.h&gt;
    #include &lt;stdlib.h&gt;
    /* these arrays are just used to give the parameters to 'insert',
       to create the 'people' array 
    */

    #define HOW_MANY 7
    char *names[HOW_MANY]= {"Simon", "Suzie", "Alfred", "Chip", "John", "Tim",
                  "Harriet"};
    int ages[HOW_MANY]= {22, 24, 106, 6, 18, 32, 24};

    typedef struct person
    {
      char *name;
      int age;
      struct person *next;
    }Person;
    static int compare_people(Person *p1, Person *p2)
    {     
      return strcmp(p1-&gt;name, p2-&gt;name);
    }

    static Person* insert_sorted(Person *headp, char *name, int age) 
    {
      Person *p = malloc(sizeof(Person)); 
      if (p == NULL)
        abort();
      p-&gt;name = name;
      p-&gt;age = age;
      if (headp == NULL)
      {
        headp = p;
        return p;
      }
      else
      {
        Person *current = headp;
        Person *temp =NULL;
        while(current != NULL &amp;&amp; compare_people(current, p) &lt; 0)
        {
          temp = current;
          if(compare_people(current,p) &gt; 0)
           break;
          current = current-&gt;next;
       }
        p-&gt;next = current; 
        temp-&gt;next = p;
       return headp;
      }

    }  
    int main(int argc, char **argv) 
    {
      Person *people2 = NULL;
      for (int i = 0; i &lt; 7; i++) 
      {
        people2 = insert_sorted(people2, names[i], ages[i]);
        //printf ("name: %s, age: %i\n", people2-&gt;name, people2-&gt;age);
      }

      while(people2 != NULL)
      {
        printf ("name: %s, age: %i\n", people2-&gt;name, people2-&gt;age);
        people2 = people2-&gt;next;
      }
      return 0;
    }
</code></pre>