home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch8 / stackex.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  37 lines

  1. /*                         stackex.c
  2.  *
  3.  *   Synopsis  - A driver program to test the stack utilities. 
  4.  *               This program accepts a line of input from 
  5.  *               standard input and displays the first eight
  6.  *               characters in reverse order to standard output.
  7.  *   Objective - To demonstrate and test the stack utilities.
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12. #include "stack.h"                                /* Note 1 */
  13.  
  14. /* Constant Definitions */
  15. #define BUF_SIZE                 80
  16.  
  17. int main( void )
  18. {
  19.      char inbuff[BUF_SIZE];
  20.      int index;
  21.      STACK st;                                 /* Note 2 */
  22.  
  23.      printf( "Enter a line of characters : " );
  24.      fgets( inbuff, BUF_SIZE, stdin );
  25.  
  26.      init_stack( &st );                        /* Note 3 */
  27.      for ( index = 0; inbuff[index] != '\0'; index++ ) {
  28.           push( inbuff[index], &st );
  29.      }
  30.  
  31.      while ( !is_empty( st ) ) {
  32.           putchar( pop( &st ) );
  33.      }
  34.      putchar( '\n' );
  35.      return 0;
  36. }
  37.