Error in qsort function in Programming Pearls?

Posted by Dervin Thunk on Stack Overflow See other posts from Stack Overflow or by Dervin Thunk
Published on 2009-07-02T02:04:48Z Indexed on 2010/05/13 9:44 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

Hello, is it just me or this code in Programming Pearls is wrong (quicksort wants 2 const voids, no?) If so, is my solution right? Apologies, just learning...

int wordncmp(char *p, char* q)
{   int n = k;
    for ( ; *p == *q; p++, q++)
    	if (*p == 0 && --n == 0)
    		return 0;
    return *p - *q;
}

int sortcmp(char **p, char **q)
{   return wordncmp(*p, *q);
}
...

qsort(word, nword, sizeof(word[0]), sortcmp);

Is this a solution?

int sortcmp(const void *p, const void *q)
{   return wordncmp(* (char * const *) p, * (char * const *) q);
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about stdlib