Xref: utzoo comp.lang.c:25879 comp.unix.xenix:10058 Path: utzoo!attcan!uunet!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!spocm2!spodv5!jha From: jha@spodv5.UUCP (Johan Harsta) Newsgroups: comp.lang.c,comp.unix.xenix Subject: Re: qsort() - HELP Message-ID: <144@spodv5.UUCP> Date: 13 Feb 90 13:10:46 GMT References: <5916@ozdaltx.UUCP> Organization: Philips TDS, Stockholm, Sweden Lines: 45 In article <5916@ozdaltx.UUCP>, root@ozdaltx.UUCP (root) writes: > After going over the manuals more times than I'd like, I still can't > figure out how to get qsort() (S) to operate. The example shows > something like: > > void qsort(base, nel, width, compar) > char *base > unsigned nel, width > int (*compar)() > > Is base supposed to be an array? - 'base' should be a pointer to the base of the table, and of type pointer to an element in the table, casted to a pointer to character > nel & width are self-explanitory > What is compar() looking for or how is it assigned? - 'compar' is supplied by you; e.g. 'strcmp' or a modified version of it E.g.: struct ELEMENT buffer[nele]; sort_buf (&buffer[0], nele); void sort_buffer (base, nele) struct ELEMENT *base; int nele; { qsort ((char *) base, (unsigned) nele, (unsigned) sizeof (struct ELEMENT), sorting_alg); return; } int sorting_alg (arg1, arg2) char *arg1; char *arg2; { return (strncmp (arg1, arg2, MAX_RELEVANT_CHARACTERS)); } Something like the above should work, good luck! /Johan Harsta, Programator Uppsala AB, Sweden (consultant for Philips)