Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created January 17, 2016 12:51
Show Gist options
  • Save krysseltillada/e0a585bbed06dbd15bc6 to your computer and use it in GitHub Desktop.
Save krysseltillada/e0a585bbed06dbd15bc6 to your computer and use it in GitHub Desktop.
ex 4-13 (c the programming language 2 ed) reverse recursion
#include <stdio.h>
#include <string.h>
void reverse (char str[])
{
static char temp[100];
static int i = 1;
static int first = 0;
static int last;
last = strlen (str) - i;
temp[first++] = str[last];
++i;
if (last <= 0) {
temp[first] = '\0';
strcpy (str, temp);
return;
}
reverse (str);
}
int main ()
{
char str [] = {'h', 'e', 'l', 'l', 'o', '\0'};
reverse (str);
printf ("%s ", str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment