Click to See Complete Forum and Search --> : /usr/include


zonked
10-21-2002, 12:03 AM
I'm new to C++ and trying to use the strcmpi() function. I found a tutorial which claimed it resided in string.h. But it isn't. I can grep string.h and see that it's not.

Are the common .h files (say string.h for instance) standardized? Or should I expect to find slightly different versions of each on different systems/compilers?

Thanks...

l01yuk
10-21-2002, 06:02 AM
The header files are standardised to a point, there is a definition of what the standard header files must contain but some compilers have extra extentions to these so you have to be careful that what you are using is actually a standard function. strcmpi() is not a standard C++ function so it may not be present in all c++ compilers.

You can roll your own version of this function quite easily though since all it most likely does is change letters to upper or lower case in a copy of the array before comparing them.


int my_strcmpi(char *one, char *two)
{
char one_c[MAX], two_c[MAX];

strcpy(one_c,one);
strcpy(two_c,two);

/*
convert all letters in one_c and two_c to
upper case using a for loop, isalpha() and
toupper().
*/

return strcmp(one_c,two_c);
}
NB. Code is only intended to explain an unproven idea, it is in no way intended as the complete answer.

bwkaz
10-21-2002, 02:06 PM
Correct, strcmpi() (and in fact a lot of functions, especially like stuff in conio.h) aren't standard (C99) C functions, so they may not exist on all platforms, and they might be named differently if they do exist.

Anyway, I'm not sure if strcmpi() is what I think it is (I'm thinking of a stricmp() function), but does the strcasecmp() function do what you need? (check the man page for strcasecmp to find out)

zonked
10-21-2002, 05:37 PM
Thanks guys, that answered my question and gave me 2 ways to workaround the problem. Really appreciate it.

I'm having a good time with the C++ , I've only done JavaScript and PHP before, so it's fun for me to deal with a language that's clearer even if it's harder. Can't wait to build apps not called "foo" or "lesson3". :-D