palindrome ??

palindrome ??
Hi guys. so I have been trying to solve this problem and I wrote a bit of which I think its part of the solution. so I would apreciate a help from you guys.

~~~~~~~~~~~~~
A palindrome is a word, phrase, or any other sequence of letters that can be spelled the same way in either direction. For example, “level” and “noon” are palindromes. Write a recursive logical-function that returns 1 if the word is a palindrome and 0 otherwise. You may do it by matching the first letter with the last, the second with the next-to-last, and so on. Matching letters should be non-case- sensitive that is upper case letters match lower case letters. Notice that a single letter is not considered a palindrome.
Write a driver (main) function to prompt the user to enter a sentence. Use your recursive logical- function to count the number of palindromes in that sentence. You need to use String Tokenization (strtok) function to split the sentence into words.
1. This looks like a homework.
2. The idea is to copy a reversed word to another variable, and to check if they are equal to each other.
Thanks EssGeEich that was very helpful.

but this is not a homework this is a problem from an old exam :)
any more help guys?? at least some hints.
Last edited on
You mention that you wrote a bit, which you think is part of the solution. So what it it??
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define SIZE 81

int fun(char str[],int size);
int rec_fun(char str[],int size);

int main(void){
int sum;
char str[SIZE];
printf("Enter a sentence: \n");
sum=fun(str, SIZE);
gets(str);
rec_fun(str,SIZE);
printf("the sentance have %d pelidorum", sum);

getch();
return(0);
}

int fun(char str[],int size){
int flag, i, len, sum=0;

len=strlen(str);
for(i=0; i<len/2; i++){
if(tolower(str[len+i])==tolower(str[len-1])){
flag=1;
continue;}
else
flag=0;
break;}
if(flag)
sum+=1;
return sum;
}

int rec_fun(char str[],int size){
char *token; int sum;
token= strtok(str," ");

if(NULL)
return 0;
else
return fun(strtok(token,NULL), size);
}


can any one point out the problem?
Topic archived. No new replies allowed.