/*Exit handlers allow you to have the program execute some code before exiting*/ #include static void ExitHandling(void); int main (void) { /*We pass the exit handler to the atexit function, which executes it on exit*/ /*atexit can accept multiple functions, and executes them in reverse order.*/ if (atexit(ExitHandling) != 0) printf("My exit handler does not work\n"); printf("This is the main program running.\n"); return(0); } /*The exit handling code below...*/ static void ExitHandling(void){ /*Exit handling code goes here*/ printf("This is the exit handler talking.\n"); } /*Example borrowed from (& fully explained in) */ /*"Advanced Programming in the Unix Environment" by*/ /*W. Richard Stevens & Stephen Rago */