0

I have strings that may contain character 0. They are stored in a structure like this:

typedef struct somestruct_s {
     const unsigned char *string;
     size_t length;
};

If I wish to compare 2 of these together I can use memcmp as such:

int match = (a->length == b->length) ? !memcmp (a->string, b->string, a->length) : 0;

But if I wish to compare 2 of these together without regard to case, my first instinct is to use strncasecmp/_strnicmp -- however, that function stops on null characters.

Is there a common C function already around that can do this. I don't mind writing my own, but before I do I want to make sure there isn't a standard function that I am unaware of.

B. Nadolson
  • 2,988
  • 2
  • 20
  • 27
  • 1
    `memicmp` is the case insensitive version – wero Apr 09 '16 at 10:16
  • memicmp, cool. Thanks! – B. Nadolson Apr 09 '16 at 10:23
  • roll your own style for non-Microsoft compilers --- http://web.mit.edu/jhawk/mnt/spo/os2/ftp/emx/emx/lib/str/memicmp.c – B. Nadolson Apr 09 '16 at 10:27
  • 3
    It helps if you think of "I have strings that may contain character 0" as "so these are **not** strings". – Jongware Apr 09 '16 at 10:59
  • A string is a general programming language term not exclusive to C. The type of strings in C are often referred to as "C strings" or null-terminated strings. There were strings before the C programming language was ever invented. In many languages, a string can contain a NULL and they are still called strings. – B. Nadolson Apr 09 '16 at 12:50

0 Answers0