/* hw5p2b.c */


#include <stdio.h>

#define MAXWORDLEN 20

void GetWord (char word[]);
void Reverse (char word[], char rev[]);

void main()
{
  char word[MAXWORDLEN];
  char rev[MAXWORDLEN];
  GetWord(word);
  Reverse(word, rev);
  printf("reverse is %s\n", rev);
}

void GetWord (char word[])
{
  int i;
  printf("enter a word: ");
  for (i = 0; (word[i] = getchar()) != '\n'; i++); /* getchar until newline */
  word[i] = '\0';   /* put null character at end or word */
}

void Reverse (char word[], char rev[])
{
  int i, j;
  for (i = 0; word[i] != '\0'; i++);  /* advance i to point to end of word[] */
  for (j = i - 1; j >= 0; j--)
    rev[i-j-1] = word[j];      /* copy from back of word[] to front of rev[] */
  rev[i] = '\0';               /* null terminate the new reversed word */
}
