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 can you read a directory in a C program?
What happens if header file is included twice?
How to write a code for reverse of string without using string functions?
What is a nested loop?
Why use int main instead of void main?
What is memory leak in c?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
hi, which software companys will take,if d candidate's % is jst 55%?
Explain how can I pad a string to a known length?
When can you use a pointer with a function?
What are header files in c programming?
How many types of errors are there in c language? Explain
Explain setjmp()?
What is cohesion and coupling in c?
What is the purpose of sprintf?