/* Strings, functions and things */

#include <stdio.h>

char *reverse(char *string);

void main(void) {

  char msg[35] = "Oxford University Computer Society";
								/* Setup string */

  printf("%s\n", msg);                  /* Print normal string */
  reverse(msg);                         /* Reverse string */
  printf("%s\n", msg);                  /* Print reversed string*/
  printf("%s\n", reverse(msg));         /* Reverse string back and 
                                           print*/
}

/* Reverse function */

char *reverse(char *string) {

  int i;
  int length, half_length;
  char buffer;

  length = strlen(string);             /* length does not include 
                                           '\0' */

  half_length = length / 2;            /* Fractional parts dropped 
                                          */

  /* Swap characters from the back of the string to the front and 
     vice versa */

  for(i=0; i<half_length; i++) {
    buffer = string[i];
    
    string[i] = string[length - 1 - i];
    string[length - 1 - i] = buffer;
  }

  string[length + 1] = '\0';           /* Terminate string */

  return(string);                      /* Return string, allowing
                                          neat nesting inside
                                          printf */
}
/* OUTPUT
 *           Oxford University Computer Society
 *           yteicoS retupmoC ytisrevinU drofxO
 *           Oxford University Computer Society
 */
