Recursive method to implement string reversal function

A recursive function is a function that calls itself inside a function. It is solved by breaking down complex problems into smaller sub-problems. Recursive functions usually consist of two parts: the base case and the recursive call. Please use the recursive method to implement the C language function for string reversal.

#include <stdio.h>

void reverseString(char* str)
{
    ///Begin///
    // 递归基
    if(*str=='\0')
        return;

    // 递归调用
   reverseString(str+1);

    End

    // 输出当前字符
    printf("%c", *str);
}

int main()
{
    char str[100];

    printf("Enter a string: \n");
    scanf("%s", str);

    printf("Reversed string: \n");
    reverseString(str);
    printf("\n");

    return 0;
}

Take hello as an example

Guess you like

Origin blog.csdn.net/m0_70732442/article/details/133994057