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
what do you mean by enumeration constant?
What does == mean in texting?
which is an algorithm for sorting in a growing Lexicographic order
Differentiate between #include<...> and #include '...'
Is calloc better than malloc?
What is the difference between fread buffer() and fwrite buffer()?
What is wrong with this statement? Myname = 'robin';
What is a stream in c programming?
What is the newline escape sequence?
What is the importance of c in your views?
What are near, far and huge pointers?
why do some people write if(0 == x) instead of if(x == 0)?
What is the general form of #line preprocessor?
write a c program for swapping two strings using pointer
What is external variable in c?