delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/04/07:59:00

Sender: crough45 AT amc DOT de
Message-Id: <97Aug4.135334gmt+0100.17050@internet01.amc.de>
Date: Mon, 4 Aug 1997 12:56:40 +0100
From: Chris Croughton <crough45 AT amc DOT de>
Mime-Version: 1.0
To: Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE
Cc: djgpp AT delorie DOT com
Subject: Re: "Missing" functions

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 -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019