Reversing a string in c with recursion

后端 未结 11 765
遥遥无期
遥遥无期 2021-01-22 09:47

I have written code to reverse a string in c... it works fine but I can\'t return the reversed string in the main() function.

#include

        
11条回答
  •  滥情空心
    2021-01-22 10:09

    You need to modify the string, i.e. the input buffer to reverse(), instead of just printing it.

    Doing this recursively seems a bit obnoxious, but should of course be possible.

    Basically, I guess the printing becomes an assignment, something like this:

    1. Base: The reversal of an empty string is the empty string.
    2. Step: The reversal of a string begins by swapping the first and last characters, then recursing over the remainder of the string.

提交回复
热议问题