I'm having trouble understanding how this reverse function works. I've tried working out what the code does step-by-step on paper, but it's not making sense to me. The best (albeit crude) interpretation I have of what the code does is this:
http://s7.postimg.org/632xhovwr/recursion_confusion.png
#include <stdio.h>
#include <string.h>
#define MAX 1000
void reverse(char s[]);
main()
{
char str[] = "remotes";
printf("Before: %s\n",str);
reverse(str);
printf("After: %s\n",str);
system("Pause");
return 0;
}
void reverse(char s[])
{
static int i = 0, n;
char c = s[i];
if (c != '\0') {
++i;
reverse(s);
s[n-i] = c;
--i;
}
else {
n = i;
}
}
Normally I don't have trouble with recursive functions when the recursion is the last step of the code since you apply recursion until some terminating condition and sort of cascade backwards. But when there's code before and after the recursive call, it makes things a lot more confusing.

static, and not used before it is set when the 0-terminator is reached. - Daniel Fischerstaticvariables because it doesn't want to soil its public interface. Really classy. - Jon