convert pointer to pointer to void pointer

Posted by FihopZz on Stack Overflow See other posts from Stack Overflow or by FihopZz
Published on 2012-11-05T03:20:25Z Indexed on 2012/11/05 5:00 UTC
Read the original article Hit count: 380

Filed under:
|

When I'm learning to use qsort to sort an array of string, there is a question puzzled me. For example, to sort the following s

 char *s[] = {
                   "Amit",
                   "Garima",
                   "Gaurav",
                   "Vaibhav"
                };

To use the qsort, you must provide a comparison function like the following function cstring_cmp I guess in the qsort function, the type of parameter to be passed to the function cstring_cmp is char**. How to convert a char** to a void*? Why can we convert a char** to a void*?

    int cstring_cmp(const void *a, const void *b)
    {
        const char **ia = (const char **)a;
        const char **ib = (const char **)b;
        return -strcasecmp(*ia, *ib);
        /* return the negative of the normal comparison */
    }

© Stack Overflow or respective owner

Related posts about c

    Related posts about void-pointers