Topical Information

This lab should provide you with practice with string manipulation (and libraries). (classes are pretty much useless here. *grin*)

Program Information

Write a function that allows case-insensitive comparison 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.)

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.

Thought Provoking Questions

  1. How do you compare two characters without reference to case? How might you do this without destroying the character variable(s) contents?

  2. 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!)

  3. What kind of arguments should your string comparison function take? (Value, reference, constant?)

  4. 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?

  5. 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).