On Tue, 29 Apr 2003, Michael Barton wrote:
> qsort can sort any way you want, you just have to provide your own
> comparison function.
>
> from qsort(3)
> The comparison function must return an integer less than, equal to, or
> greater than zero if the first argument is considered to be respectively
> less than, equal to, or greater than the second. If two members compare as
> equal, their order in the sorted array is undefined.
>
> from strcmp(3)
> The strcmp() function compares the two strings s1 and s2. It returns an
> integer less than, equal to, or greater than zero if s1 is found,
> respectively, to be less than, to match, or be greater than s2.
Of course you have to remember that strcmp is NOT an alphabetic comparison.
It simply compares the ASCII values of the characters. This means that
all upper case characters come after all lower case letters. Using
strcmp, this is how these words would sort:
apple
cat
Bell
BALL
dog
If you want to sort alphabetically, where "Bell" comes BEFORE "cat",
there is a function in linux (it's not a standard C function), strcasecmp(),
which ignores upper and lower case. You could also write your own.
The compare() from a couple of emails ago, using TOLOWER, was close, but
needed a few more lines of code.
Dennis