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

What is selection sort in c?

611


What is adt in c programming?

611


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

667


write a c program to calculate sum of digits till it reduces to a single digit using recursion

2718


If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402

3247






how do you execute a c program in unix.

636


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

1592


What is meant by preprocessor in c?

536


What is a null pointer in c?

595


What should malloc(0) do?

615


In c language can we compile a program without main() function?

580


What is the auto keyword good for?

626


What is a global variable in c?

588


What are the disadvantages of external storage class?

590


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1879