Reverse a string using a recursive function

后端 未结 5 1875
悲哀的现实
悲哀的现实 2021-01-22 09:10

I am currently studying C and I can\'t get past this exercise. I must create a recursive function to reverse string1 into string2. Here is my code. I w

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-22 10:04

    I have corrected the program. Please find the changes below

    void reverse(char s1[],char s2[],int n,int j)
    {
     if(n>0)
     {
            s2[j]=s1[n-1];
            reverse(s1,s2,--n,++j);
     }
     else
            s2[j]='\0';
    }
    

提交回复
热议问题