Processing Strings as Character Arrays – Part I

The next big step is to write a function called testForPalindrome, which does what its name obviously suggests. However, we will write another helper function first, which testForPalindrome will call to make it's own job much easier. So in this step, we will first write a function called convertToCanonical(), which takes a single C-string (i.e., an array of chars), and will preprocess the string to turn it into a canonical form, by removing all spaces, commas, and periods (the ' ', ',', and '.' chars). The function modifies its argument--the actual contents of the array that is passed in is modified in-place--so it doesn't need to return a value, and should be declared "void". (We leave it up to you to figure out what the function declaration/prototype should look like.)

So, if convertToCanonical() is given the string: "Hello , world . ", it should return: "helloworld"
.

Something important to note about the char array passed in: we do not have to also pass in the size of the array as we've done elsewhere. This is because:

  1. It contains a proper C-string, meaning it is null-terminated; and
  2. the modified string is guaranteed to be equal to or shorter than the original string
This means that if you are clever, you can do the conversion completely within the array that was passed in, without needing another array. However, if you would like to use another array, you can declare one locally using "char tmpArray[MAX_STR]". If you do use another temporary array to do the processing, make sure you copy the final results back into the array that was passed in, though.