qsort() - HELP

David Nugent david at csource.oz.au
Wed Feb 14 04:50:58 AEST 1990


 > From: root at ozdaltx.UUCP (root)
 > Date: 12 Feb 90 14:55:54 GMT
 > Organization: OZ BBS - Dallas, TX
 > Message-ID: <5916 at 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 at csource.oz.au
Via FidoNet 3:632/348, Central Source ICBS, Melbourne, Australia



More information about the Comp.unix.xenix mailing list