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 / error.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  44 lines

  1. /*                     error.c
  2.  *
  3.  *   Synopsis  - This code contains compile time errors. Its 
  4.  *               intent is purposely vague.
  5.  *
  6.  *   Objective - To illustrate the compiler's understanding of 
  7.  *               local variables and their scope.
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12.  
  13. /* Function Prototypes */
  14. int addit( void );
  15. /* PRECONDITION:  none.
  16.  *
  17.  * POSTCONDITION: Attempts to add sum to counter. Has syntax errors.
  18.  *
  19.  */
  20.  
  21. int main( void )
  22. {
  23.      int counter;                                /* Note 1 */
  24.  
  25.      for ( counter = 1; counter < 5; counter++ ) {
  26.           int i;                                 /* Note 2 */
  27.           i = counter;                           /* Note 3 */
  28.           i = i + 5;
  29.           addit();
  30.      }
  31.                                                  /* Note 4 */
  32.      printf( "i was %d; addit() returned %d.\n", i, addit() );
  33.      return 0;
  34. }
  35.  
  36. /*******************************addit()*************************/
  37.  
  38. int addit( void )
  39. {
  40.      int sum = 0;                                 /* Note 5 */
  41.  
  42.      sum = sum + counter;                         /* Note 6 */
  43.      return ( sum );
  44. }