How to reverse a string using a recursive function, without
swapping or using an extra memory?

Answer Posted / d g patel

/* Following code does as intended */
#include <stdio.h>

#define REVERSE_STRING(X) Rstring(X, *(X), strlen(X)-1)

void Rstring( char *str, char c, int index )
{
if( index != 0 )
Rstring( str, *(str+(strlen(str))-index),
index-1);
*(str+index) = c;
}

int main( void )
{
char str[] = "Dharmendra Patel";
printf("Actual string is [%s]\n", str);
REVERSE_STRING(str);
printf("Reversed string is [%s]\n", str);
return 0;
}

Is This Answer Correct ?    92 Yes 46 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In C programming, how do you insert quote characters (‘ and “) into the output screen?

898


What is strcpy() function?

660


List some basic data types in c?

561


What are bitwise shift operators in c programming?

650


What is data structure in c and its types?

598






Difference between strcpy() and memcpy() function?

683


How can I find out if there are characters available for reading?

649


Explain output of printf("Hello World"-'A'+'B'); ?

979


What are the 4 data types?

604


Where register variables are stored in c?

554


What are the 32 keywords in c?

639


Who invented bcpl language?

709


What is the value of c?

576


What is #include in c?

602


What are two dimensional arrays alternatively called as?

663