/**********************************************************************
 * reverse.c --- Read, reverse, and echo a line from stdin.
 **********************************************************************/


#include <stdio.h>


#define LINE_LENGTH 80


int main()
{
   char line[LINE_LENGTH];       /* Input buffer. */
   char *prompt = "Enter a line to be echoed.\n";
   char *nl = "\n";

   char *s0;                     /* Pointer to beginning of line. */
   char *s1;                     /* Pointer to end of line. */
   char temp;

   printf("%s", prompt);            /* Prompt user and read input. */
   fgets(line, LINE_LENGTH, stdin);
   printf("%s", nl);

   s0 = line;

   s1 = line;

   while (*s1 != '\n')       /* Find the last character in the line */
      ++s1;

   --s1;

   while (s0 < s1)           /* Reverse the string. */
   {
      temp = *s0;
      *s0 = *s1;
      *s1 = temp;
      ++s0;
      --s1;
   }

   printf("%s", line);

   return 0;
}
