~Rick wrote: > At Sunday 5/4/2008 01:42 AM, you wrote: >> ~Rick wrote: >>> Hi all, >>> >>> I currently call qsort to sort an array of structures. It works fine, >>> but I would like to sort multiple fields. Can this be done? Is there >>> another, or better, sort available to do this? Do I somehow do this >>> in my compareEntry routine? >>> >>> Here is the call I am using currently: qsort(linedata, (bufcnt - 1), >>> sizeof(ENTRY), compareEntry); >>> >>> linedata is an array of (ENTRY) structures, bufcnt-1 is the number of >>> structures to sort. >>> >>> >>> ~Rick >> If field 1 is identical, then fall through to field 2. If field 2 is >> identical, then fall through to field 3. And so on, for all the fields >> you want to sort on. The value you return from the comparison function >> tells whether the first ENTRY structure is less than, equal, or greater >> than the second ENTRY structure. > > Thank you for the reply, Thomas. But I'm still a bit unclear how to proceed. > > My comparison function is called directly by qsort, so I don't get to > see the results (although I guess I could assign a value to a variable). > Where do I check the value(s) for the secondary fields, within the > compare function or after qsort returns? If I check after qsort > returns, do I call qsort again with a field offset somehow? > > Thanks, > > ~Rick
You do it all inside the comparison function. When two fields are identical, you move to the next field. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
