/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  reverse.c                       by Alan Partis, ThunderNet Productions   */
/*                                  (c) Copyright 2001. All rights reserved. */
/*                                                                           */
/*  Reverses each line of input from stdin and writes it to stdout.          */
/*                                                                           */
/*  Functions:                                                               */
/*      main()      program entry point                                      */
/*      reverse()   reverses a given char array                              */
/*                                                                           */
/*  Date        who     Comments                                             */
/*  -----------------------------------------------------------------------  */
/*  02dec01     acp     initial creation                                     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <stdio.h>
#include <string.h>
#include <thundernet.h>
#include "reverse.h"


//
// local constant definitions
//
#define MAX_LINE_LENGTH     1024


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  main()                          by Alan Partis, ThunderNet Productions   */
/*                                  (c) Copyright 2001. All rights reserved. */
/*                                                                           */
/*  Program entry point.  Executes program algorithm.                        */
/*                                                                           */
/*  args:   argc        number of command line arguments                     */
/*          argv        array of command line argument strings               */
/*                                                                           */
/*  return: int         program exit status                                  */
/*                                                                           */
/*  Date        who     Comments                                             */
/*  -----------------------------------------------------------------------  */
/*  02dec01     acp     initial creation                                     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main (int argc, char *argv[])
{

    char    line_in[MAX_LINE_LENGTH];

    while (fgets(line_in, MAX_LINE_LENGTH, stdin) != NULL) {
        printf("%s", reverse(line_in));
    }

    printf("\n... the end\n");

}   /* end of function main() */



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  reverse()                       by Alan Partis, ThunderNet Productions   */
/*                                  (c) Copyright 2001. All rights reserved. */
/*                                                                           */
/*  Assumes the given input is a string of byte-sized characters and simply  */
/*  reverses their order.  No new memory is allocated -- the reversed string */
/*  replaces the original source in place.                                   */
/*                                                                           */
/*  args:   source      pointer to source array                              */
/*                                                                           */
/*  return: target      pointer to reversed array                            */
/*                                                                           */
/*  Date        who     Comments                                             */
/*  -----------------------------------------------------------------------  */
/*  02dec01     acp     initial creation                                     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
char *reverse(char *source)
{
    char   *end;
    char   *start;
    char    tmp;

    start = source;
    end = start + strlen(source) - 1;

    while (end > start) {
        tmp = *start;
        *start++ = *end;
        *end-- = tmp;
    }

    return source;

}   /* end of function reverse() */


  Copyright © Thundernet Development Group Inc., 2003.
All rights reserved.