Recursion. I checked other online solutions and they seem to be pretty much identical to mine.
The code should reverse the string (in its position) but it does not. E.g when input is st2 = "abcdefg" the output is an empty string. I was expecting st2 = "gfedcba". What am i missing?
void recurse_reverse(char s, int sz)
int i=0,j = sz -1;
void swap( char* s1, char *s2)
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
char st1 = "abcdefg", st2;
printf("s1 = %s\ns2 = %s",st1,st2);
You are swapping the 2 zero bytes at the end of
st1. Hence, the
st2 starts with a null byte and thus the printf() isn't printing anything.
You just need to fix your argument passing. Instead of
You probably want to add logic to make sure your destination array
st2 has sufficient space.