This lab should provide you with practice with string manipulation, looping, function design, and perhaps even libraries.
Write a function that allows case-insensitive comparison (aka ordering) of two strings. The strings should not be altered at all. The return value should be analogous to that from string::compare():
s1 < s2 return something < 0 s1 == s2 return something == 0 s1 > s2 return something > 0
(Hint: 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! For efficiency, you cannot use any local string variables in your function — just the two arguments. Neither string argument may be altered.
Even more, you may not alter the two string arguments before you send them to the function, either!
Call your function something useful (strcmp_ncase?).
Write a driver program to test your function.
How do you compare two character values without regard to case? Does this require you to destroy the character variable(s) contents?
How can you access a single character from within a string?
How can you range an integer-typed variable through a known sequence of values...say from 0 to not quite my_string_var.size() but stop early if a special event happens?
How can you compare two strings in a case-insensitive way without destroying their contents? (Remember: You should not change the strings in order to compare them!)
What kind of arguments should your string comparison function take? (I.E. 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? (Hint: recall the inherited C propensity to view characters as ASCII codes — aka integers.)
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? Maybe a driver should employ some form of yes/no looping mechanism?
(Tip: Would a yes/no helper function come in handy to simplify this looping code and remove most of those details from your driver...helping you to focus on simply testing the comparison function?)
This assignment is (Level 2.5).
Add (Level 1) to place your new function in a library. Add another (Level 0.5) to append it to the strextra library you made for one of the other labs.
Add (Level 1) to add two defaulted arguments to your function which will allow the caller to request that you ignore/skip spaces and/or punctuation when doing the comparison.
Add (Level 2) to have numbers within the strings compare properly even when they aren't justified with leading 0's or spaces. That is, we want these strings to compare like this: "2" should come out less than "10".
Don't forget about isdigit from cctype and about that other lab — they might help...
Add (Level 3) to have numbers within the strings compared/ordered properly even if they aren't in the lead of the string. So, "a2" would report as before "a10" and both would report to be before "b1".