man qsort
says:
The contents of the array are sorted in ascending order according to a comparison function
pointed to by compar
, which is called with two arguments that point to the objects being compared.
It's clear that "with two arguments that point to the objects being compare". So when comparing two char *
strings, the argument are in type "pointers to pointers to char
", which is also covered in the manpage:
static int
cmpstringp(const void *p1, const void *p2)
{
/* The actual arguments to this function are "pointers to
pointers to char", but strcmp(3) arguments are "pointers
to char", hence the following cast plus dereference */
return strcmp(* (char * const *) p1, * (char * const *) p2);
}
And man strcmp
will tell you that its prototype is:
int strcmp(const char *s1, const char *s2);
where the arguments are "pointers to char
".
Therefore the conversion solves this.
You may need to read the manpage carefully.