Syntax
#include <stdlib.h> int atexit(void (*func)(void));Description
atexit records a function, pointed to by func, that the system calls at normal program termination. For portability, you should use atexit to register up to 32 functions only. The functions are executed in a LIFO (last-in-first-out) order.
atexit returns 0 if it is successful, and nonzero if it fails.
This example uses atexit to call the function goodbye at program termination.
#include <stdlib.h>
#include <stdio.h>
void goodbye(void)
{
   /* This function is called at normal program termination                   */
   printf("The function goodbye was called at program termination\n");
}
int main(void)
{
   int rc;
   rc = atexit(goodbye);
   if (rc != 0)
      perror("Error in atexit");
   return 0;
   /****************************************************************************
      The output should be:
      The function goodbye was called at program termination
   ****************************************************************************/
}
Related Information