Thinking in terms of recursion can be a little tricky. Without going into the details as to why or why not to use recursion, let's assume it has to be recursion (homework, discovery, whatever the reason).
So the main thing to consider for recursion is what the terminating condition is. If you have trouble doing so, maybe writing the algorithm in an iterative fashion can help you.
In this instance, what you need to determine is when the character array ends. This will be the case if the current character is '\0'
.
A simple recursive algorithm might be:
- Check current character. Is it '\0' ?
- Yes: Return 0
- No. Is the current character a letter?
- Yes: return 1 + call this function with incremented character pointer
- No: return 0 + call this function with incremented character pointer
Note that this algorithm will not terminate after seeing a non-letter character, so " test a" will return 5, not 4. If you have to terminate before, you would need some type of flag, that gets passed to the function.
Anyway, my main point was to think of what the terminating condition should be.