title: Abort trap: 6 on Mac when trying to run program with quicksort
body: <p>So, I'm trying to run the following C program, and all I get when I run it is an error that says: </p>
  
  <blockquote>
    <p>Abort trap: 6</p>
  </blockquote>
  
  <p>Any ideas why? This only happens when I run the quicksort algorithm. I think it has something to do with the recursion, but it should work fine, so I don't know what's going on.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define MAX_DIM 30
  
  int partition(char**, int, int); 
  void quickSort(char**, int, int);
  
  int main()
  {
      char **array;
      array = (char**) malloc(6*sizeof(char*));
      for(int i = 0; i &lt; 6; i++)
      {
          array[i] = (char*) malloc(MAX_DIM*sizeof(char));
      }
      strcpy(array[0], "ok");
      strcpy(array[1], "bye");
      strcpy(array[2], "then");
      strcpy(array[3], "yeah");
      strcpy(array[4], "lets");
      strcpy(array[5], "go");
      quickSort(array, 0, 5);
      for(int i = 0; i &lt; 6; i++)
      {
          printf("%s\n", array[i]);
      }
  
      return 0;
  }
  
  void quickSort(char **a, int l, int r)
  {
      int j;
      if( l &lt; r )
      {
          j = partition( a, l, r);
          quickSort( a, l, j-1);
          quickSort( a, j+1, r);
      }
  }
  
  int partition(char **a, int l, int r) {
      int i, j;
      char pivot[MAX_DIM], t[MAX_DIM];
      strcpy(pivot, a[l]);
      i = l; j = r+1;
      while(1)
      {
          do ++i; while( strcmp(a[i], pivot) &lt;= 0 &amp;&amp; i &lt;= r );
          do --j; while( strcmp(a[j],pivot) &gt; 0);
          if( i &gt;= j ) break;
          strcpy(t, a[i]); strcpy(a[i], a[j]); strcpy(a[j], t);
      }
  
      strcpy(t, a[l]); strcpy(a[l], a[j]); strcpy(a[j], t);
      return j;
  }
  </code></pre>