is there a way to use strcmp so that it is not case sensitive?
For instance, if I call strcmp(value, "string"), and value is either String or STRING, I will still return a true.
Thanks for your help
is there a way to use strcmp so that it is not case sensitive?
For instance, if I call strcmp(value, "string"), and value is either String or STRING, I will still return a true.
Thanks for your help
strcmpi()
works like strcmp() , but without case sensitivity.
My Tutorials :
- Bad programming practices in : C
- C\C++ Tips
(constrcutive criticism is very welcome)
- Brain Cell
Some C libraries support stricmp() -- a non-standard call -- which ignores case
If your C doesn't have it try something like this:
Code:#include <ctype.h> /* case blind strcmp */ int stricmp (const char *p1, const char *p2) { register unsigned char *s1 = (unsigned char *) p1; register unsigned char *s2 = (unsigned char *) p2; unsigned char c1, c2; do { c1 = (unsigned char) toupper((int)*s1++); c2 = (unsigned char) toupper((int)*s2++); if (c1 == '\0') { return c1 - c2; } } while (c1 == c2); return c1 - c2; }
Borland Turbo C used to have stricmp(). I have never encountered strcmpi() in a C library.
What environment supports that?
looks like strcmpi() is C++
strcasecmp() is C [edit] (GNU) [[/edit] and is not case sensitive.
dinjas
Last edited by dinjas; 03-15-2005 at 05:29 PM. Reason: added Gnu
straight off the heap
strcmpi() is supported by VC++6 and DevC++ (delcared in string.h). I'm not sure if its standard or not though.
My Tutorials :
- Bad programming practices in : C
- C\C++ Tips
(constrcutive criticism is very welcome)
- Brain Cell
You're thinking probably of stricmp, also another non-standard command. Like so.
Quzah.
Hope is the first step on the road to disappointment.
thanks for all of your help
By the way, when writing your own implementation you should avoid starting the name of the function with the characters "str" as it violates the C symbol naming standard (there's more rules than just not starting with "str"). If you try to compile that function with a compiler that has stricmp() then you'll get redefinition warnings or errors.
If you understand what you're doing, you're not learning anything.