I'm trying to do a recursive function with C to check if a word is a palindrome or not (read in both ways).
It's the first time I use this kind of function, but I have a problem, I don't know why it doesn't work, if you could help me, there's my code, thanks :
#include <stdio.h>
#include <string.h>
int palindrome(char c[100],int i, int j)
{
if (j == i)
{
return 1;
}
// Si le premier et le dernier caractère
// sont les mêmes alors, on peut commencer les tests
if(c[i] == c[j])
{
// On fais les tests pour chaque caractère de la chaine
return palindrome(c, i++, j--);
} else {
return 0;
}
return 0;
}
int main(void)
{
char chaine[100] = "radar";
int pal;
pal = palindrome(chaine, 0, strlen(chaine)); // Returns : 0 -> False / 1 -> True
printf("%d", pal);
return 0;
}