R
Richard Herring
Won't behave correctly if either of the strings contains embedded '\0',David Fisher said:#include <cctype> // for tolower()
#include <cassert>
// returns < 0 if s1 < s2, > 0 if s1 > s2 or 0 if the strings
// are equal (without regard to case)
// ie. behaves like strcmp()
int stricmp(const char *s1, const char *s2)
{
while (*s1 && *s2)
{
if (tolower(*s1++) != tolower(*s2++))
{
return (int) tolower(*s1) - (int) tolower(*s2);
}
}
return (*s1 ? 1 : (*s2 ? -1 : 0));
}
int stricmp(std::string s1, std::string s2)
{
return stricmp(s1.c_str(), s2.c_str());
}
as comparison will stop at the first one.