Journey of a simple recursive code

Some one asked the following question in StackOverflow

Implement a function with prototype char *repeat(char *s, int n) so that it creates and returns a string which consists of n repetitions of the input string s. For example: if the input is “Hello” and 3, the output is “HelloHelloHello”. Use only recursive constructs.

I immediately started compiling the answer as it was a pretty straight forward question. But it was not only me who was posting the answer. So after posting, very quickly other answers started appearing. It was a general everyday answer, until a person (who also answered the question) pointed out a bug in my code. Bugs disturb the mind. So I dug into the code and fixed it. The things started to get challenging when others started to get more compact code, which didn’t let me sit idle.
Continue reading “Journey of a simple recursive code”

Advertisement