Recursive Word Reversal

This function prints out the words in a sentence reversed. The function uses recursive calls to itself. The definition of words is any sequence of characters delimited by one or more spaces. The resulting printout should include only one space between words, with no spaces before the first word or after the last word. Therefore, the input string can have multiple spaces between words, or before and after the string, but the result should not preserve those.

The bug does not involve the stack potentially overflowing because of excessive recursion—assume that is not an issue.

For this example, the length of the string is ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.