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
Why is extern used in c?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays
What is wrong with this program statement?
What is the method to save data in stack data structure type?
Add Two Numbers Without Using the Addition Operator
How was c created?
How #define works?
Is null a keyword in c?
What the different types of arrays in c?
int i=10; printf("%d %d %d", i, i=20, i);
Write a program to print numbers from 1 to 100 without using loop in c?
Write a program to check whether a number is prime or not using c?
In C language what is a 'dangling pointer'?
Why pointers are used?
What is size of union in c?