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

How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include...

4894


How to Throw some light on the splay trees?

608


shorting algorithmS

1786


Who developed c language?

626


Is c procedural or object oriented?

561






How can I implement a delay, or time a users response, with sub-second resolution?

610


How can I do serial ("comm") port I/O?

672


What is the g value paradox?

625


How do we print only part of a string in c?

574


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3102


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

567


What are derived data types in c?

598


What is meant by realloc()?

662


What is floating point constants?

676


What are 'near' and 'far' pointers?

603