The compare
function receives pointers to items in the array. Since the array items here are pointers to char
, what it receives is pointers to pointers to char
:
int compare(const void* p, const void* q)
{
char **a= (char**)p;
char **b= (char**)q;
return strcmp(*a,*b);
}