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
Can you assign a different address to an array tag?
What does the message "automatic aggregate intialization is an ansi feature" mean?
What does the function toupper() do?
Explain the use of fflush() function?
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
Is main is user defined function?
What is dynamic variable in c?
What is difference between Structure and Unions?
How do I round numbers?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What functions are in conio h?
What are the c keywords?
What is scope of variable in c?
What is the difference between ++a and a++?
What is variable declaration and definition in c?