Skip to main content
GameDev.net gamedev.net
🔒 Locked

comparing strings

Started by Silent Angel Dec 17, 2004 at 2:36 PM 2 replies 450+ views
Original Post
Silent Angel
Silent Angel
hello i want to compare two strings in order to put them alphabetically ordered... but, how can i do this? strcmp doesn't help me, does it? i really need some help :(
Pipo DeClown
Pipo DeClown
strcmp() and strcmpi() return 0 if there is no difference. Maybe you expected it to return true.
Enigma
Enigma
What language are you using? If you're using C++ just use std::strings and compare with operator<.

Enigma
ProPuke
ProPuke
strcmp does help you. Any lookup on documentation on it will tell you that it returns a value marking the relation between the first & second parameter strings. -1 meaning the first is lower in ascii order & +1 meaning it is higher.
So it will tell you quite nicely what order they go in.
Also the strcmpi ignores case & seems to accomplish what you want perfectly, but as Enigma said - in c++ it's good to get into the habit of using the c++ libraries & std::string has much nice handling for such things
____ _ ___ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.