<div dir="ltr">It might be a stupid mistake but I'm puzzled. I'm trying to sort an array of strings which is the file listing for a directory. Based on manpages, online docs and forums I'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's erroring out during the sort.<div>
<br></div><div>Here'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's what's needed by qsort. I've also tried writing my own compare function with strcmp in it and I get same results.</div>
<div><br></div><div>It's quite puzzling.</div><div><br></div><div>Here's an example output before and after qsort by running ls on /sys on Ubuntu so it's doing something but almost like it'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>