/*=============================================================================
Filename: reverse.c
Purpose : Reverses a string in place
Author  : Tristan Miller -- psy@cs.toronto.edu

Study questions:
  * Why do we need to subtract 1 in lines (a) and (b)?
  * Can you rewrite this program to work without using any functions from
    <string.h>?
=============================================================================*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  char s[] = "Every good boy deserves fudge!";
  char temp;
  int i, len;

  printf("The string forwards: %s\n", s);

  len = strlen(s);

  for (i = 0; i < len / 2; i++) {
    temp = s[len - i - 1];              /* (a) */
    s[len - i - 1] = s[i];              /* (b) */
    s[i] = temp;
  }

  printf("The string reversed: %s\n", s);

  return EXIT_SUCCESS;
}

