Afficher un message
Vieux 20/10/2007, 00h44   #4
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PLEASE - odd string sorting related problem

"cpptutor2000@yahoo.com" <cpptutor2000@yahoo.com> writes:
> Could some C guru provide some hints on my problem? I am trying to
> 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.


What's obvious about that?

> I can convert all the non-digit characters to
> lowercase, but how do I deal with the non-alphanumeric characters?


I don't know. How do you want to deal with non-alphanumeric characters?

Using strcmp() directly is certainly a valid way to sort strings, but
you apparently want to map uppercase letters to lowercase before
comparing them. That still leaves a plethora of ways you might want
to compare strings that contain things other than letters. We have no
way of knowing (and C doesn't define) which of those ways is valid.

You need to decide how you want to do the comparisons. Once you've
done that, it's likely you'll be able to implement the comparison in C
yourself. If not, show us what you've tried and we can you fix
it.

--
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"
  Réponse avec citation
 
Page generated in 0,05061 seconds with 9 queries