Mail Archives: djgpp/1997/08/04/07:59:00
Robert Hoehne wrote:
> Use strcasecmp() instead, which is more partable
> and the same.
In what way is strcasecmp more portable than stricmp?
I've never seen strcasecmp on any other compiler, and
stricmp is at least standard on PC compilers and a lot
of the older Unices (Borland, at least, had 'strcmpi'
as a macro alias for 'stricmp').
The fact is, there is no portable case-independent
string comparison function unless you write it yourself.
It's one of the oddities in the ANSI library - Plauger
just says "The set of functions is incomplete and
inconsistent", but doesn't mention case-independent
compare as one of the lacks. Strange, since most
implementations before the ANSI deliberations did
include it (either stricmp or strcmpi, sometimes also
combinations like strnicmp) and much of the ANSI string
deliberations were about locale issues where case folding
would logically have a place.
Several of my programs include something like the
following:
#include <ctype.h>
#define stricmp(x,y) __My_stricmp(x,y)
int __My_stricmp(const char *x, const char *y)
{
while (*x && *y && tolower(*x) == tolower(*y))
{
if (*x != *y)
return (tolower(*x) > tolower(*y) ? 1 : -1);
x++;
y++;
}
if (*x || *y)
return (*x ? 1 : -1);
return 0;
}
so that they are independent of the existence of it
in the library...
Chris C
- Raw text -