the function, IsPalindrome is recursive. it checks character array from 0 to end of it.
i have warning message control reaches end of non-void function...
whats wrong with this code?

int main()
{
   length = strlen(string);
   boolean = IsPalindrome(string, 0, length);
...
}

int IsPalindrome (char* string, int left, int right)
{
   if (left >= right)
   {
      return TRUE;
   }
   if (string == string)
   {
      return IsPalindrome(string, left+1, right-1);
   }
   if (string != string)
   {
      return FALSE;
   }      
}

Recommended Answers

All 3 Replies

Aside from the fact that you dont give the length and boolean variables types, using reserved words and variable names and using an int function to return a boolean?

See the comment I added at the bottom of the code

int main()
{
   length = strlen(string);
   boolean = IsPalindrome(string, 0, length);
...
}

int IsPalindrome (char* string, int left, int right)
{
   if (left >= right)
   {
      return TRUE;
   }
   if (string == string)
   {
      return IsPalindrome(string, left+1, right-1);
   }
   if (string != string)
   {
      return FALSE;
   }      
   //// The compiler is complaining about no return 
   //// statement here.  It can't tell that the program 
   //// can't reach this point.
}

As a matter of fact, the last IF is not needed at all. If the previous IF ( if (string == string) ) fails, the strings are automatically !=, isn't it? Also, when can string ever be not equal to string ? They are the same variable, therefore they MUST be equal!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.