This lab should provide you with practice with string manipulation (and libraries). (classes are pretty much useless here. *grin*)
Write a function that allows case-insensitive comparison (aka ordering) of two strings. The return value should be analogous to that from strcmp:
s1 < s2 return something < 0 s1 == s2 return something == 0 s1 > s2 return something > 0
(These return values can be short integers.) (You are NOT allowed to use the library functions strcasecmp or stricmp as they are not standard or portable. You are tasked with writing your own version here!)
Just remember that the comparisons are to be done in a manner that ignores the case of the letters in the strings!
But also note that the strings should not be altered at all. Don't change the two string arguments before or during the call. Don't make copies and change the copies. All of this is terribly wasteful and/or destructive of data.
Place your new function in a library (strextra?) and call it something useful (strcmp_ncase?).
Write a driver program to test your function.
How do you compare two characters without reference to case? How might you do this without destroying the character variable(s) contents?
How can you compare two strings in a case-insensitive way without destroying their contents? (You should not change the strings in order to compare them!)
What kind of arguments should your string comparison function take? (Value, reference, constant?)
How do you get that weird return value for your function? Is it always -1, 0, 1? Or is there a reason it was defined as simply less than 0, 0, or greater than 0?
How many times will you need to call your function to test it thoroughly? How many times should you have to run the driver to do this testing?
This assignment is (Level 1.5).
Add (Level 1.5) to add two defaulted arguments to your function which will allow the caller to request that you skip spaces and/or skip punctuation when doing the comparison.
Add (Level 1) to add a defaulted argument to your function which will allow the caller to request that you stop at a certain maximum number of characters when doing the comparison. This should be 0 when they want you to compare the whole string or a valid positive number when they want you to compare, say, 5 characters at most. Of course, don't run off the end of either string while doing this!
Add (Level 2) to modify your function to have numbers in the strings compared/ordered properly even when they aren't justified with leading 0's. That is, "2" should compare negative to "10" instead of positive as it does now.
Don't forget about isdigit from cctype and about that other lab — they might help...
Add (Level 3) to have numbers compared/ordered properly even if they aren't in the lead of the string. Have "a2" come before "a10" but "a10" come before "b1".