I got an undeclared identifier error from the follow code, but i have clearly declared the variable “length” in both cases. what did I do wrong?
int startWordLenRec(char s[]) {
if (isLetter(s) == false){
int length = 0;
}
else if{
int length = 1 + startWordLenRec(s+1);
}
return length;
}
A declaration is local to the scope you declare it in. So if you declare it inside
{}, it cannot be used after the closing}.Of course, you can also
return 0;directly, without a separate variable.