Reversing a string in c with recursion

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

    This code is not executable :( You define int reverse but reverse function doesnt return any value

    instead use this (using void):

    #include
    
    main()
    {
      char a[17]="abcdefg";
      reverse(a);
      printf("\n");
      system("PAUSE");
    }
    void reverse(char *a)
    {
       if(*a!='\0')
       {   
         reverse(a+1);
       }
       printf("%c",*a);
    }        
    

提交回复
热议问题