Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Newsgroups: comp.lang.c Subject: Re: Function-types: compatability, and typedefs Message-ID: <1989Sep1.113440.28300@jarvis.csri.toronto.edu> Date: 1 Sep 89 15:34:40 GMT References: <19361@mimsy.UUCP> <1996@munnari.oz.au> Distribution: comp Lines: 21 ok@cs.mu.oz.au (Richard O'Keefe) writes: >If you want to sort an array of strings, e.g. > char *myarray[N_Of_Strings]; > ... > qsort(myarray, N_Of_Strings, sizeof myarray[0], {{SOMETHING}}) >**don't** try to pass 'strcmp' as the fourth argument of qsort()... >What you need is > int strptrcmp(char **s1, char **s2) > { return strcmp(*s1, *s2); } Actually, you should write int strptrcmp(void *s1, void *s2) { return(strcmp(*(char **)s1, *(char **)s2)); } The original form will only work when the representation of (char **) is the same as the representation of (void *), something not guaranteed by ansi C and in fact not true on all machines (albeit true on most). ajr