Im trying to run this code...
Code:
#include <stdio.h>
#include <string.h>
// Recursive palindrome finder function
bool palindrome(char* word, int length);
int main() {
char word[100];
printf("Please enter a word to see if it is a palindrome: "); // Get word from user
scanf("%s",&word);
if((palindrome(word,strlen(word))) == 1) { // If palindrome returns true, say its a palindorme...
printf("%s is a palindrome\n",word);
}
else {
printf("%s is not a palindrome\n",word); // Otherwise, say it isnt
}
return 0;
}
// Recursive palindrome finder function
bool palindrome(char* word, int length) {
int i=0;
char tempWord[100];
int length;
if(strlen(word) == 1) { // If the word is only 1 letter long, it is a palindrome
return true;
}
else {
if(word[0] == word[(strlen(word) - 1)]) { // If first letter equals the last letter...
for(i = 0; i < strlen(word); i++) {
tempword[i] = word[(i+1)]; // Cut the first and last letters off the word...
}
strcpy(word,tempWord);
length = strlen(word);
palindrome(word,length); // Rerun recursive function
}
else {
return false;
}
}
}
...but Im getting these errors:
--------------------Configuration: cc - Win32 Debug--------------------
Compiling...
c.c
C:\Documents and Settings\**********\Desktop\cc\c.c(4) : error C2061: syntax error : identifier 'palindrome'
C:\Documents and Settings\**********\Desktop\cc\c.c(4) : error C2059: syntax error : ';'
C:\Documents and Settings\**********\Desktop\cc\c.c(4) : error C2059: syntax error : 'type'
C:\Documents and Settings\**********\Desktop\cc\c.c(13) : warning C4013: 'palindrome' undefined; assuming extern returning int
C:\Documents and Settings\**********\Desktop\cc\c.c(23) : error C2061: syntax error : identifier 'palindrome'
C:\Documents and Settings\**********\Desktop\cc\c.c(23) : error C2059: syntax error : ';'
C:\Documents and Settings\**********\Desktop\cc\c.c(23) : error C2059: syntax error : 'type'
Error executing cl.exe.
c.obj - 6 error(s), 1 warning(s)