I need a case insensitive string comparison function similar to strcmp...where can I view the code sample of it?
please help
thank you
Printable View
I need a case insensitive string comparison function similar to strcmp...where can I view the code sample of it?
please help
thank you
It's simple enough to make your own. Just loop through each string changing the characters to lower case, then use strcmp(). Well, that's one way, there are more... ;)Quote:
Originally posted by Unregistered
I need a case insensitive string comparison function similar to strcmp...where can I view the code sample of it?
please help
thank you
You'll need to use isupper() and tolower() at least.....
Actually, you'll need only 'toupper' or 'tolower' only. One or the other. No need for both, no need to even bother checking. Just run a loop and compare tolower(letter1) with tolower(letter2).Quote:
Originally posted by Hammer
You'll need to use isupper() and tolower() at least.....
You can pass tolower a lower case value, or hell, even a number or punctuation mark, and it'll just return any non-upper case characters as they were, unchanged. The only thing it changes is upper case.
Quzah.
or if your homework does not require you to write your own you could use
lstrcmpi() (windows version of stricmp() )
if(lstrcmpi(sString1,sString2)==0)//they are the same
just use stricmp....
>just use stricmp....
Why? The functionality is trivial to program and far more portable if done correctly. Remember that stricmp is not a standard function, so not all implementations will have it. With a little thought and effort, you can write your own function in ISO conforming code and not have to worry about portability problems.
-Prelude