Re: PLEASE - odd string sorting related problem
On Oct 19, 8:28 pm, gordonb.hw...@burditt.org (Gordon Burditt) wrote:
> >Could some C guru provide some hints on my problem? I am trying to
>
> It might if you STATE A PROBLEM.
>
> >sort an array of character strings, where each string contains
> >lowercase, uppercase, digits as well as non-alphanumeric characters as
> >'-', '(' or '/'. Obviously, standard C functions as 'strcmp' would
> >fail in these cases.
>
> It is obvious to me that strcmp() would succeed in comparing any C
> strings whatever, as long as you put no requirements on sort order
> that conflict with what strcmp() does (and you didn't say anything
> about sort order at all).
>
> >I can convert all the non-digit characters to
> >lowercase, but how do I deal with the non-alphanumeric characters?
>
> It isn't necessary to convert punctuation to lower case in any
> character set I'm aware of.
>
> It is generally considered a hanging offense to deal characters
> from the bottom of the deck.
As far as I remember from my trusty K & R C text,
the source code for the strcmp fumction is:
int strcmp(const char *s1, const char *s2)
{
while (*s1 == *s2++)
if (*s1++ == 0)
return (0);
return (*(const unsigned char *)s1 - *(const unsigned char *)
(s2 - 1));
}
Given that, I am trying to find a way of sorting strings for example:
1. Bungie.net - TCP623
2. Doom(Id Sofware) - version 1
Obviously, the non-digit and non-alphanumeric (a -> z, A - > Z) cannot
be converted to lower case, how do I deal with these special
characters - straightforward application of 'strcmp' would not provide
very accurate results.
|