qsort() - HELP

Vasco Pedro vp at fctunl.rccn.pt
Tue Feb 13 22:07:53 AEST 1990


In article <5916 at ozdaltx.UUCP> root at 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 at host.fctunl.rccn.pt
Phone: (+351) (1) 295-4464 (1360)   ARPA: vp%hara.fctunl.rccn.pt at 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



More information about the Comp.lang.c mailing list