title: C++ Recursion and Pointer Problems
body: <p>First off, this is for an assignment.</p>
  
  <p>What's required: </p>
  
  <pre><code>1.Take in string input
  2. copy string (stripping out white space, punctuation, and 
     covert all characters to uppercase in the process)
  3. Then determine if this copied string is a palindrome.
  </code></pre>
  
  <p>The method required for determining a palindrome:</p>
  
  <pre><code>Base Case:  string length is &lt;= 1
  General Case: if first letter != last letter, false, otherwise
                 point to next letter and write '\0' to last letter and
                 call the method again
  </code></pre>
  
  <p>For example:</p>
  
  <pre><code>RACECAR\0   R==R
  ACECA\0     A==A
  CEC\0       C==C
  E\0         E &lt;= 1  TRUE!
  </code></pre>
  
  <p>I cannot get my isPalindrome function to work correctly. Everything else is spot on, as far as I can tell. I really think the problem lies in my recursive call. I have been debugging this for 2 days and I cannot figure why the return is wrong. Any help would be GREATLY appreciated. I'm not looking for a hand out, maybe just some extra eyes on this code. Thanks.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cctype&gt;   
  using namespace std;
  
  int charCount(char  * copy)
  {
      int count = 0;
  
      for (int i = 0; copy[i] != '\0'; i++)
      {
          count++;
      }
  
      return count;
  }
  
  bool isPalindrome(char *copy)
  {
      bool result = false;
      int size = charCount(copy);
  
      char * last = &amp;copy[size - 1];
  
      if (size &lt;= 1)
      {
          result = true;
      }
  
      if (copy != last)
      {
          result = false;
      }
  
      else
      {
          ++copy;
          last = '\0';
          isPalindrome(copy);
      }
  
      return result;
  }
  
  void stringCopy(char * source, char * destination)
  {
      int sourceIndex = 0;
      int destIndex = 0;
  
      while (source[sourceIndex] != '\0')
      {
          while (!(isalnum(source[sourceIndex])) &amp;&amp; source[sourceIndex] != '\0')
          {
              sourceIndex++;
          }
  
          if (source[sourceIndex] == '\0')
          {
              break;
          }
  
          if (isalpha(source[sourceIndex]))
          {
              destination[destIndex] = toupper(source[sourceIndex]);
          }
  
          if (isdigit(source[sourceIndex]))
          {
              destination[destIndex] = source[sourceIndex];
          }
  
          sourceIndex++;
          destIndex++;
      }
  
      destination[destIndex] = '\0';
  }
  
  int main()
  {
      string input = "";
  
      cout &lt;&lt; "Enter a string: ";
      getline(cin, input);
  
      char * source = &amp;input[0];
      int sourceSize = charCount(source);
  
      char * copy = new char[sourceSize];
  
      stringCopy(source, copy);
  
      int copySize = charCount(copy);
  
      if (isPalindrome(copy))
      {
          cout &lt;&lt; input &lt;&lt; " is a palindrome!" &lt;&lt; endl;
      }
  
      else
      {
          cout &lt;&lt; input &lt;&lt; " is not a palindrome" &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>