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
Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given
Can you please explain the scope of static variables?
What are the data types present in c?
What is auto keyword in c?
in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.
What is break statement?
What is #line in c?
Can we change the value of #define in c?
What are the main characteristics of c language describe the structure of ac program?
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
how to construct a simulator keeping the logical boolean gates in c
c program to compute AREA under integral
What does typeof return in c?
What is hungarian notation? Is it worthwhile?
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above