I am trying to compile the following very very simple piece of source code:
#include
// #include
// using namespace std;
cl
Add a define for it to overwrite stricmp with strcasecmp on the platforms you are looking for.
#ifdef _IPHONE <- your platform define here
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif
Then you can just use stricmp always.
Try strcasecmp()
. Here's the manual page for it. It is conforming to 4.4BSD and POSIX.1-2001.
Pretty easy to make your own if need be...
int my_stricmp (const char *s1, const char *s2)
{
while (*s1 != 0 && *s2 != 0)
{
if (*s1 != *s2 && ::toupper (*s1) != ::toupper(*s2))
{
return -1;
}
s1++;
s2++;
}
return (*s1 == 0 && *s2 == 0) ? 0 : -1;
}
If you've got Boost, use boost::algorithm::iequals(s1, s2, std::locale::classic())
in <boost/algorithm/string/predicate.hpp>
(or leave off locale if you want locale-sensitivity). It works with C strings, std::[w]string
, vector<char>
, etc.
stricmp is neither POSIX nor ANSI, so it doesn't really matter if strcmp
is allowed, if your compiler or standard library is strictly adhering to POSIX or ANSI standard library functions (as is probably the case with the GCC suite).