home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list13_9.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  801b  |  45 lines

  1.  /* Demonstrates the exit() and atexit() functions. */
  2.  #include <stdio.h>
  3.  #include <stdlib.h>
  4.  #include <time.h>
  5.  #define DELAY 150000
  6.  
  7.  void cleanup( void );
  8.  void delay( void );
  9.  
  10.  main()
  11.  {
  12.      int reply;
  13.  
  14.     /* Register the function to be called at exit. */
  15.  
  16.      atexit( cleanup );
  17.  
  18.      puts("Enter 1 to exit, any other to continue.");
  19.      scanf("%d", &reply);
  20.  
  21.      if (reply == 1)
  22.          exit( EXIT_SUCCESS );
  23.  
  24.      /* Pretend to do some work. */
  25.  
  26.      for (reply = 0; reply < 5; reply++)
  27.      {
  28.          puts("Working...");
  29.          delay();
  30.      }
  31.  }       /* End of main() */
  32.  
  33.  void cleanup( void )
  34.  {
  35.      puts("\nPreparing for exit...");
  36.      delay();
  37.  }
  38.  
  39.  void delay(void)
  40.  {
  41.      long x;
  42.      for( x = 0; x < DELAY; x++ )
  43.          ;
  44.  }
  45.