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
What is a rvalue?
What are the two forms of #include directive?
Is it possible to have a function as a parameter in another function?
Does free set pointer to null?
Find MAXIMUM of three distinct integers using a single C statement
What is the advantage of using #define to declare a constant?
Why is c platform dependent?
How do you define CONSTANT in C?
What is variable in c example?
What is the difference between ++a and a++?
what is different between auto and local static? why should we use local static?
How can this be legal c?
how can f be used for both float and double arguments in printf? Are not they different types?
what are the different storage classes in c?
What is the difference between exit() and _exit() function?