title: How do I sort the elements of argv in C?
body: <p>I am trying to alphabetically sort the elements of argv. </p>
  
  <p>The following line of code is giving me problems: </p>
  
  <pre><code>qsort(argv[optind], argc - optind, sizeof(argv[optind]), sort);
  </code></pre>
  
  <p>Specifically, the last argument is giving me trouble, the comparison function, which is given below: </p>
  
  <pre><code>int
  sort(const void *a, const void * b)
  {    
      return(strcmp( (char*)a, (char*)b ));
  }
  </code></pre>
  
  <p>At the moment, it compiles fine, but I end up getting a segmentation fault when I run it. </p>