Code:
int strcmp_nocase (const string S1, const string S2)
{
string::const_iterator p1 = S1.begin ();
string::const_iterator p2 = S2.begin ();
while (p1 != S1.end () && p2 != S2.end ())
{
if (toupper (*p1) != toupper (*p2))
{
if (toupper (*p1) < toupper (*p2))
{
return -1;
}
else
{
return 1;
}
}
++p1;
++p2;
}
if (S1.size () == S2.size ())
{
return 0;
}
else if (S1.size () < S2.size ())
{
return -1;
}
else
{
return 1;
}
}
you should be able to tweek the code to do case sensitive comparisons. you can also see there are ways to toupper (tolower would be the same) a string. not too hard.