title: qsort to compare strings for alphabetical order
body: <p>I'm using the <code>qsort()</code> that comes with the <code>stdlib.h</code> library to sort an array of structures of strings.</p>
  
  <p>It's essentially an array of strings but with a structure that is containing the array.</p>
  
  <p>For example:</p>
  
  <pre><code>typedef struct node {
    char name[MAX_SIZE + 1];
  } Node;
  </code></pre>
  
  <p>Then my array of nodes that contains the names would be:</p>
  
  <pre><code>Node nodes_list[MAX_SIZE + 1];
  </code></pre>
  
  <p>My question is, I want to sort <code>nodes_list</code> so when I print the following: </p>
  
  <pre><code>for (i = 0; i &lt; size; i++) {
     printf("%s\n", nodes_list[i].name);
  }
  </code></pre>
  
  <p>it prints all the names in alphabetical order.</p>
  
  <p>I would like to do sort the list using <code>qsort</code> and my comparator function is this:</p>
  
  <pre><code>int compare(const void *a, const void *b) {
    const char **ia = (const char **)a;
    const char **ib = (const char **)b;
    return strcmp(*ia, *ib);
  }
  </code></pre>
  
  <p>when I run the function with <code>qsort</code>:</p>
  
  <pre><code>qsort(nodes_list, size, sizeof(Node), compare);
  </code></pre>
  
  <p>I get a segmentation fault (core dumped).</p>
  
  <p>I know I am getting a segmentation fault with this snippet of code because without it, I can print the list of names fine. Not sorted of course.</p>
  
  <p>Can someone help?</p>