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
In C programming, how do you insert quote characters (‘ and “) into the output screen?
What is strcpy() function?
List some basic data types in c?
What are bitwise shift operators in c programming?
What is data structure in c and its types?
Difference between strcpy() and memcpy() function?
How can I find out if there are characters available for reading?
Explain output of printf("Hello World"-'A'+'B'); ?
What are the 4 data types?
Where register variables are stored in c?
What are the 32 keywords in c?
Who invented bcpl language?
What is the value of c?
What is #include in c?
What are two dimensional arrays alternatively called as?