Ok, I have read several other questions basically asking the same thing, but I know this code can work instead of using other peoples work. Yes, i'm stubborn. I have written a function to be called from my main program and i keep getting an error that I cannot figure out. Please look over the below code and see if you can help me determine what is wrong with the line "palindrome(string[1]);". I know it must be something terribly simple, but for some reason, I cannot see it. Any ideas out there? Thanks you to anyone that can assist.
int palindrome(const char *string)
{
int ans;
char sub[MAX_LEN];
if (strlen(string) <= 1) {
ans = 1;
} else if (string[0] != string[strlen(string)-1]) {
ans = 0;
} else {
palindrome(string[1]); /* this should be testing for the next element in the array on each pass, compared to the next to last element in the array */
ans = palindrome(sub);
}
return (ans);
}