Reputation: 33
!isalpha( str[first] ) ? ( return isPalindrome( str, ++first, last ) ) : return isPalindrome( str, first, --last ) ;
I get a syntax error.
Upvotes: 1
Views: 74
Reputation: 183251
That's not allowed, because return
is not allowed inside an expression; it's only allowed at the top-level of a statement. (Any expression can be used as a statement, but the reverse is not true.) You can write either this:
return !isalpha(str[first])
? isPalindrome(str, ++first, last)
: isPalindrome(str, first, --last);
or this:
if (!isalpha( str[first] )) {
return isPalindrome( str, ++first, last );
} else {
return isPalindrome( str, first, --last );
}
Upvotes: 6
Reputation: 20838
return !isalpha(str[first]) ?
isPalindrome(str, ++first, last) :
isPalindrome(str, first, --last);
Upvotes: 4