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
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
How to Throw some light on the splay trees?
shorting algorithmS
Who developed c language?
Is c procedural or object oriented?
How can I implement a delay, or time a users response, with sub-second resolution?
How can I do serial ("comm") port I/O?
What is the g value paradox?
How do we print only part of a string in c?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
What are derived data types in c?
What is meant by realloc()?
What is floating point constants?
What are 'near' and 'far' pointers?