title: qsort crashing program - C
body: <p>Trying to follow <a href="http://www.anyexample.com/programming/c/qsort__sorting_array_of_strings__integers_and_structs.xml" rel="nofollow noreferrer">this</a> example. (Section String sorting...)<br>
  Is there anything obvious that would make this crash in stdlib's qsort.c?<br>
  I also tried <em>cstring_cmp</em> with strncmp specifying 30 chars max, much more than I have.<br>
  *fileArray[20] seems to be correctly populated with strings.<br>
  Thanks. </p>
  
  <pre><code>char* ptr_fileName;  
  char* fileArray[20];//number of files  
  size_t strings_len;  
  
  ptr_fileName = (char*)malloc((strlen(FindFileData.cFileName)+1)*sizeof(char));
  memcpy(ptr_fileName, FindFileData.cFileName, strlen(FindFileData.cFileName)+1);
  fileArray[i] = ptr_fileName;
  
  
  
  strings_len = sizeof(fileArray) / sizeof(char *);          
  qsort(fileArray, strings_len, sizeof(char *), cstring_cmp);   
  //crashing in qsort.c
  </code></pre>
  
  <p>qsort c-string compare function:</p>
  
  <pre><code>/* qsort C-string comparison function */
      int cstring_cmp(const void *a, const void *b)
      {
          const char **ia = (const char **)a;
          const char **ib = (const char **)b;
          return strcmp(*ia, *ib);
          /* strcmp functions works exactly as expected from
          comparison function */
      }
  </code></pre>