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
the question is that what you have been doing all these periods (one year gap)
Explain the use of fflush() function?
What is the method to save data in stack data structure type?
What is build process in c?
What are the 4 types of unions?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
What is #define?
What are the advantages of c preprocessor?
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
What is array in c with example?
Write a program to check prime number in c programming?
What are integer variable, floating-point variable and character variable?
How can you determine the size of an allocated portion of memory?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
What are the data types present in c?