"cpptutor2000@yahoo.com" <cpptutor2000@yahoo.com> writes:
[...]
> 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));
> }
That's one possible definition for strcmp() (I'll assume it's correct,
but I haven't taken the time to check it). But strcmp() is specified
in terms of how it behaves. It needn't even be implemented in C.
> 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.
What. Are. You. Trying. To. Do. ???.
What do you mean by "accurate"?
There is no one definition of how to compare strings. You've told us
that you want to treat corresponding upper and lower case letters as
if they were equal ('A' and 'a' equal). You haven't given us a clue
about how you want to deal with non-alphanumeric characters.
For example, if you're comparing "foobar" vs. "FooBarBaz", you
apparently want to map all letters to lowercase, then use strcmp() to
compare "foobar" vs. "foobarbaz" (result: "foobar" < "FooBarBaz").
What if you're comparing "foo.bar" vs. "foo:bar"? What result do you
want? Do you want them to compare equal? Do you want "foo.bar" <
"foo:bar"? or "foo.bar" > "foo:bar"? Or do you not care as long as
you get a consistent ordering? Any of those would be equally correct.
We can't possibly guess how to accomplish your goal if you won't tell
us what your goal is.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"