How to reverse a string using a recursive function, without
swapping or using an extra memory?

Answer Posted / prakash

Another version that actually reverses the string...

#include <stdio.h>

char *reverse(char *sstr, char *str, char c)
{
if (*str == '\0')
return sstr;

sstr = reverse(sstr, str+1, *(str+1));

*sstr = c;

return (sstr+1);
}

int main()
{
char str[100];

printf("Enter the string: ");
scanf("%s", str);

reverse(str, str, *(str + 0));
printf("Reversed string: %s\n", str);

return 1;
}

Is This Answer Correct ?    25 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

834


What are categories used for in c?

794


What is void main ()?

793


What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

859


Who is the main contributor in designing the c language after dennis ritchie?

758


Explain what are binary trees?

818


Can include files be nested? How many levels deep can include files be nested?

851


What is 'bus error'?

848


What is a stream?

871


How do I get an accurate error status return from system on ms-dos?

851


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

865


while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

973


please help me..... please codes and flowchart plz turbo c lang po yan.....please asap response... 3. Make an astrology program. The user types in his or her birthday (month, day, and year as integer), and the program responds with the user’s zodiac sign, horoscope, and other information related to it. If the user’s birth year falls into a leap year, your program should display an appropriate message for it. NOTES: Conditional Statements: it should be with graphics

3084


How can I get back to the interactive keyboard if stdin is redirected?

864


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

1647