PDA

View Full Version : Strcmp C++ Function Question




bobber205
Mar 5, 2007, 09:08 PM
At school I use Visual Studio.

And there's a function there called 'stricmp' which compares two strings insenstive to case.

While I could make a temp char array, and lower case both paramters, I don't really want to have to do that.

So is there a equivalent in Xcode? I tried using stricmp but Xcode told me it wasn't declared. :(



iMeowbot
Mar 5, 2007, 09:13 PM
man strcasecmp for a family of functions that will do this.

bobber205
Mar 5, 2007, 09:19 PM
Thank you so much. :)

gnasher729
Mar 6, 2007, 08:01 AM
At school I use Visual Studio.

And there's a function there called 'stricmp' which compares two strings insenstive to case.

While I could make a temp char array, and lower case both paramters, I don't really want to have to do that.

So is there a equivalent in Xcode? I tried using stricmp but Xcode told me it wasn't declared. :(

stricmp is not a Standard C function, so you'd have to write it yourself.

Why would you make a copy? Compare characters until you find one that is different or you find the '\0' at the end. If you have different characters, convert both characters to lowercase and compare again.

Now for advanced programmers: Both strcmp and stricmp do a very simplistic way of string comparisons that gives completely unacceptable results in real life. Just have a look how iTunes sorts your albums: Very much different from what strcmp would do. For example, using strcmp or stricmp the numbers from 1 to 20 would be sorted in the order 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 3, 4, 5, 6, 7, 8, 9; iTunes gets that right. MacOS X provides a number of different ways to sort strings in the correct way, depending on your application.

iMeowbot
Mar 6, 2007, 03:37 PM
MacOS X provides a number of different ways to sort strings in the correct way, depending on your application.
These are of course not standard C functions, so you should ignore them and write them youself :rolleyes:

gnasher729
Mar 7, 2007, 04:40 AM
These are of course not standard C functions, so you should ignore them and write them youself :rolleyes:

... when you want to move your code to a Windows machine.