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
Write a program to check palindrome number in c programming?
What is the difference between if else and switchstatement
Is linux written in c?
Why ca not I do something like this?
What is the purpose of realloc()?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
writ a program to compare using strcmp VIVA and viva with its output.
What is self-referential structure in c programming?
What is a struct c#?
What does a function declared as pascal do differently?
Using which language Test cases are added in .ptu file of RTRT unit testing???
Differentiate between null and void pointers.
Under what circumstances does a name clash occur?
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.