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

  1. /* sadd.c -- a small adding machine that illustrates  */
  2. /*           the need for array bounds checking.      */
  3.  
  4. main()
  5. {
  6.     int offset = 0, i, result = 0;
  7.     int stack[3];
  8.  
  9.     while (scanf("%d", &stack[offset]) == 1)
  10.         {
  11.         ++offset;
  12.         }
  13.     for (i = 0; i < offset; ++i)
  14.         {
  15.         result += stack[i];
  16.         }
  17.     printf("-------------\n");
  18.     printf("%d\n", result);
  19.  
  20. }
  21.