/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that allocates space for a string
   dynamically, request user input, and then print the
   string backwards.  This is executed with the following
   statement:  malloc.c < malloc.in.  The contents of 
   malloc.in are: abcd */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main() {
    char *s;
    int t;
    
    s = malloc(80);
    printf("Please enter a string: ");
    if(!s) {
      printf("Memory request failed.\n");
      exit(1);
    }
    fgets(s, 80, stdin);
    printf("%s", s);
    printf("Converted string: ");
    for(t = strlen(s)-2; t>=0; t--)
      putchar(s[t]);
    printf("\n");
    free(s);
    return (0);
}
