I have one function:
int compare(char * c1, char * c2){
...
...
}
What are the various styles in which I can write a function int ret_compare(void * item) that returns a pointer to compare?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are two main styles, one using a
typedefand one not (with two variants of thetypedef). Your comparator should take constant pointers, as below:Note that these comparators cannot be used with
bsearch()andqsort()(unless you use fairly gruesome casts) because those comparators are expected to takeconst void *arguments.Note, too, that for comparing strings, as opposed to single characters, the function used by
qsort()orbsearch()should be similar to: