<div dir="ltr">It might be a stupid mistake but I&#39;m puzzled. I&#39;m trying to sort an array of strings which is the file listing for a directory. Based on manpages, online docs and forums I&#39;m using the write code and it executes without errors. However the resulting array is not sorted properly. qsort is a void function so no way to tell if it&#39;s erroring out during the sort.<div>
<br></div><div>Here&#39;s my call</div><div><br></div><div><span class="" style="white-space:pre">        </span>qsort(input, size, sizeof(char*), (int(*)(const void*, const void*))strcmp);<br></div><div><br></div><div>input is my char* array, size is the # of elements in input, sizeof(char*) size of each element, the last parameter is casting strcmp for const void since that&#39;s what&#39;s needed by qsort. I&#39;ve also tried writing my own compare function with strcmp in it and I get same results.</div>
<div><br></div><div>It&#39;s quite puzzling.</div><div><br></div><div>Here&#39;s an example output before and after qsort by running ls on /sys on Ubuntu so it&#39;s doing something but almost like it&#39;s not completing the sort?? Any ideas?</div>
<div><br></div><div><div>$ ./ls /sys</div><div>fs </div><div>devices </div><div>dev </div><div>bus </div><div>class </div><div>firmware </div><div>hypervisor </div><div>kernel </div><div>power </div><div>module </div><div>
block </div><div><br></div><div><br></div><div>firmware </div><div>hypervisor </div><div>kernel </div><div>power </div><div>fs </div><div>module </div><div>devices </div><div>block </div><div>dev </div><div>bus </div><div>
class </div></div><div><br></div><div><br></div><div><br></div></div>