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 do you mean by enumeration constant?

594


What does == mean in texting?

659


which is an algorithm for sorting in a growing Lexicographic order

1394


Differentiate between #include<...> and #include '...'

615


Is calloc better than malloc?

570






What is the difference between fread buffer() and fwrite buffer()?

669


What is wrong with this statement? Myname = 'robin';

814


What is a stream in c programming?

588


What is the newline escape sequence?

583


What is the importance of c in your views?

586


What are near, far and huge pointers?

642


why do some people write if(0 == x) instead of if(x == 0)?

652


What is the general form of #line preprocessor?

581


write a c program for swapping two strings using pointer

2092


What is external variable in c?

607