Xref: utzoo comp.lang.c:25957 comp.unix.xenix:10103 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!inesc!unl!news From: vp@fctunl.rccn.pt (Vasco Pedro) Newsgroups: comp.lang.c,comp.unix.xenix Subject: Re: qsort() - HELP Message-ID: Date: 13 Feb 90 11:07:53 GMT References: <5916@ozdaltx.UUCP> Sender: news@fctunl.rccn.pt (USENET News System) Organization: Universidade Nova de Lisboa -- Lisbon, Portugal Lines: 37 In-reply-to: root@ozdaltx.UUCP's message of 12 Feb 90 14:55:54 GMT In article <5916@ozdaltx.UUCP> root@ozdaltx.UUCP (root) writes: > > void qsort(base, nel, width, compar) > char *base > unsigned nel, width > int (*compar)() > > Is base supposed to be an array? > nel & width are self-explanitory > What is compar() looking for or how is it assigned? > Yep, 'base' is supposed to the be the (char *)base of the array you intend to sort. 'nel' is the number of elements to be sorted and 'width' the sizeof(element_to_sort). 'compar' is a pointer to int function that must behave like strcmp(s1,s2) a that will be called by qsort(...), for each two elements that will be compared, ie, if elements 2 and 4 need be compared there will be a call of the form: compar(base+(2-1)*width, base+(4-1)*width). If is strings you want to sort might just call (I think): qsort(array,nel,width,strcmp). Sorry for the inaccuracies and hope this helps. -- --- Vasco Pedro BITNET/Internet: vp@host.fctunl.rccn.pt Phone: (+351) (1) 295-4464 (1360) ARPA: vp%hara.fctunl.rccn.pt@mitvma.mit.edu Fax: (+351) (1) 295-4461 PSI/VMS: PSI%(+2680)05010310::HOST::vp UUCP: ...mcvax!inesc!unl!vp Snail: Dept. de Informatica, Universidade Nova de Lisboa 2825 Monte Caparica, PORTUGAL