Reversing a string in c with recursion

后端 未结 11 754
遥遥无期
遥遥无期 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:16

    #include 
    using namespace std;
    
    reverse( char *str)
    {
        if (*str!='\0')
        {
           reverse(str+1);
           cout<<*str;
        }
    //cout<<*str   when i am just printing here then why this is printing after one space ??
    }
    
    int main()
    {   
        string a ;  
        cin>>a;   
        reverse(&a[0]); 
        return 0;
    }
    

提交回复
热议问题