Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!munnari.oz.au!csource!david From: david@csource.oz.au (David Nugent) Newsgroups: comp.unix.xenix Subject: Re: qsort() - HELP Message-ID: <35.25D795FA@csource.oz.au> Date: 13 Feb 90 17:50:58 GMT Organization: Unique Computing Pty Limited (Vic) Lines: 48 > From: root@ozdaltx.UUCP (root) > Date: 12 Feb 90 14:55:54 GMT > Organization: OZ BBS - Dallas, TX > Message-ID: <5916@ozdaltx.UUCP> > > void qsort(base, nel, width, compar) > char *base > unsigned nel, width > int (*compar)() > > Is base supposed to be an array? Yes. > nel & width are self-explanitory > What is compar() looking for or how is it assigned? compar() is the address of a compare function. It's prototype is something like: int compar (char *, char *); > The objective is to sort an array of strings in alpha order > and then > be able to read them. So far I'm getting is core dumps. Well, fortunately strcmp() is compatible with the function. The following should work ok: qsort (base, 20, 64, strcmp); This would sort an array of strings placed in an array of 64 bytes (size of each element), and sort twenty elements into alpha order. david -- UUCP: ...!munnari!csource!david INTERNET: david@csource.oz.au Via FidoNet 3:632/348, Central Source ICBS, Melbourne, Australia