#include
#include
#include
int sortstring(const void *str1, const void *str2) {
const char *rec1 = str1;
c
What the compar
function gets are pointers to the elements in your array, which in this case, are pointers to char
. So the parameters str1
and str2
are actually pointers to pointers to char
. You must cast them like this:
int sortstring( const void *str1, const void *str2 )
{
const char *rec1 = *(char**)str1;
const char *rec2 = *(char**)str2;
int val = strcmp(rec1, rec2);
return val;
}
Then you have to use the proper element size in qsort
.
qsort(lines, 200, sizeof(char*), sortstring);