home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 308_01 / teststk.c < prev    next >
Text File  |  1990-06-17  |  993b  |  53 lines

  1.  
  2. /*
  3.     HEADER:        ;
  4.     TITLE:        Test stack -- test driver for stack module
  5.             (stk.obj);
  6.  
  7.     FUNCTION:    Reads ascii text file specified on command
  8.             line, pushing each line, then pops and prints
  9.             each line.  In effect, displays file in
  10.             reverse line order;
  11.  
  12.     FILENAME:    TESTSTK.C;
  13.     REQUIRES:    LIST.OBJ, LIST.H, STK.OBJ, STK.H, DEBUG.OBJ
  14.             DEBUG.H;
  15.     VERSION:    1.0;
  16.     DATE:        1/18/90;
  17.     AUTHOR:        Michael Kelly;
  18. */
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22.  
  23. #define DEBUG
  24.  
  25. #include "list.h"
  26. #include "stk.h"
  27. #include "debug.h"
  28.  
  29.  
  30. char input_buf[BUFSIZ];
  31. void main(int argc, char **argv)
  32. {
  33.  
  34.     FILE *fp = NULL;
  35.  
  36.     if(argc < 2)
  37.     err_exit("Useage: teststk ascii_file_name ");
  38.  
  39.     fp = fopen(argv[1],"r");
  40.     if(! fp)
  41.     err_exit("Cannot open input file");
  42.  
  43.     while(fgets(input_buf, BUFSIZ, fp))  {
  44.  
  45.     if(! push(input_buf, strlen(input_buf) + 1))
  46.         err_exit("\n\tError in Stack Push");
  47.     }
  48.  
  49.     while(pop(input_buf))
  50.     fprintf(stdout,"%s", input_buf);
  51.  
  52.  
  53. }