home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap07 / sadd2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-05  |  547 b   |  27 lines

  1. /* sadd2.c -- a small adding machine that includes */
  2. /*            array bounds checking.               */
  3.  
  4. #define MAXSTAK 3
  5.  
  6. main()
  7. {
  8.     int offset = 0, i, result = 0;
  9.     int stack[MAXSTAK];
  10.  
  11.     while (scanf("%d", &stack[offset]) == 1)
  12.         {
  13.         if (++offset >= MAXSTAK)
  14.             {
  15.             printf("Stack Full\n");
  16.             break;
  17.             }
  18.         }
  19.     for (i = 0; i < offset; ++i)
  20.         {
  21.         result += stack[i];
  22.         }
  23.     printf("-------------\n");
  24.     printf("%d\n", result);
  25.  
  26. }
  27.