Mail Archives: djgpp/2001/01/29/08:51:39
[Note: this problem is almost entirely unrelated to DJGPP --- nor even
to any particular programming language, either. You had better asked
about it elsewhere.]
D Borland <d DOT borland AT ntlworld DOT com> wrote:
[...]
> user types: 'bike green suzuki'
> programs string: 'green bike suzuki'
... and you want these two strings to compare as 'equal', right? In
that case, you'll want to preprocess both strings before comparing
them. One way would be to split each into a list of words, and sort
that list alphabetically. Then you can either concatenate those words
again, to form a new single string, or keep storing them as a sorted
list of individual strings (can be pointers into the original string,
if you kept that).
Then, you can do the comparison by using strcmp() on the sorted lists,
element by element. Due to the sorting, both of the above inputs would
end up as
"bike", "green", "suzuki"
and thus compare equal.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -