Help debug palindrome code
Hi guys!
I am learning C and am writing code to detect palindrome to help me learn to manipulate strings and use pointers and such. I am having trouble debugging it and was hoping you might be able to help.
Code:
void removeChar( char * string, char letter );
char* palindrome(char)
int main(void) {
char string[100];
printf("Enter what you think is a palindrome (w/o spaces): ");
fgets(string, sizeof(string), stdin);
palindrome(string);
return(0);
}
int palindrome(string) {
char string[100];
int n, *f, *l; //*f and *l are pointers to the first and last indexed character in string
f=&string[0]; //do I need the ampersand since it is an array?
l=&string[n];
n = strlen(string)-1;
if(string == " ") //Base case for recursion
printf("Yep! Thats is a palindrome!");
else if(string[0] == string[n])
palindrome = removeChar(string, *f); //Can I use this format instead of a character in single quotes since the
palindrome = removeChar(string, *l); //dereferenced pointers point to a singe char?
return(palindrome(string)); //check to see if the next outside characters are equal
}
void removeChar( char * string, char letter ) {
unsigned int i;
for(i = 0; i < strlen( string ); i++ )
if( string[i] == letter )
strcpy( string + i, string + i + 1 );
}