/*
 * Problem 1-19
 * Write a function reverse(s) that reverses the character string s.
 * Copyright (c) 1998 by John Weber.  All rights reserved.
 */
#include <stdio.h>

char* reverse(char*);
char* reverse_aux(char*,int,int);
void  swap(char*,char*);

int main(void)
{
	printf("car reversed is %s\n",reverse("car"));
	printf("of reversed is %s\n",reverse("fo"));
	printf("a reversed is %s\n",reverse("a"));
}

char* reverse(char* s) { return reverse_aux(s,0,strlen(s)-1); }

char* reverse_aux(char* s,int first, int last)
{
	if(last <= first) { return s; }
	else {
		swap(s+first,s+last);
		return reverse_aux(s,first+1,last-1);
	}
}
