### recursion! help!

hey :)

I've to use recoursion function that return if the string has a same letters:

for example: - fff = true
- fFf = false

I did this but the return answer is always: NOT!! why? someone know?

bool iSameLetters(char str[SIZE])
{
if(str[0]='\0')
return true;
else
{
if((str[0] && iSameLetters(str+1) == str[0]))
return iSameLetters(str+1);
return false;
}
}

Thanks!
If I have correctly understood the function has to report whether there are adjacent characters in a character array.

The function can be defined the following way (without testing)

 ``1234`` ``````bool isSameLetters( const char s[] ) { return ( s[0] && s[1] && ( s[0] == s[1] || isSameLetters( &s[1] ) ) ); }``````
Last edited on
As for your realization then it starts from a bug. Instead of the comparision operator (==) you are using the assignment operator (=)

if(str[0]='\0')
return true;
It seems I did not understand you correctly. You want to check that all characters of a string are equal each other do not you?

In this case the function will look the following way

 ``1234`` ``````bool isSameLetters( const char s[] ) { return ( !s[0] || !s[1] || ( s[0] == s[1] && isSameLetters( &s[1] ) ) ); }``````

Last edited on
Topic archived. No new replies allowed.