Turbo C & qsort()

Earl H. Kinmonth ked at garnet.berkeley.edu
Sat Feb 4 15:24:01 AEST 1989


In article <13722 at dcatla.UUCP> pmswl at sunb.UUCP (Scott W. Leonard) writes:
>
>
>
>I hope one of you C wizards can help me.  I've written a directory
>program using Turbo C 2.0.  I'm to the point of cleaning it up a
>bit.  I currently have a file sort function, but it is a bit bulky
>and time consuming.  I would really like to use Turbo's 'qsort'
>function.  I've tried it about every way possible, but nothing
>seems to work for me.

I'm not going to take the time to read through your code.  I have enough
buggy code of my own to look at. -:)  I will give you one major hint.
What qsort passes to the sort function has ONE MORE LEVEL OF INDIRECTION
than you might expect.  For example, if you are trying to sort

char	*barf[MAXBARF];

the qsort call is

qsort( (char *) barf, MAXBARF, sizeof(char **), sortfunc)

and

sortfunc(as,bs)
char	**as;
char	**bs;
{
	return(strcmp(*as,*bs));
}

Happy sorting.



More information about the Comp.lang.c mailing list