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 can you read a directory in a C program?

852


What happens if header file is included twice?

870


How to write a code for reverse of string without using string functions?

1810


What is a nested loop?

849


Why use int main instead of void main?

831


What is memory leak in c?

838


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1373


hi, which software companys will take,if d candidate's % is jst 55%?

1852


Explain how can I pad a string to a known length?

875


When can you use a pointer with a function?

736


What are header files in c programming?

826


How many types of errors are there in c language? Explain

743


Explain setjmp()?

814


What is cohesion and coupling in c?

779


What is the purpose of sprintf?

811