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
How can you avoid including a header more than once?
Why is sprintf unsafe?
Explain what are the __date__ and __time__ preprocessor commands?
What is selection sort in c?
What is the general form of function in c?
What is a null string in c?
what are the 10 different models of writing an addition program in C language?
What does the c in ctime mean?
How are Structure passing and returning implemented by the complier?
What are the types of type specifiers?
Hai what is the different types of versions and their differences
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
Ow can I insert or delete a line (or record) in the middle of a file?
What are compound statements?
What is the process to generate random numbers in c programming language?