C atexit function sets a function to call when exiting normally
Syntax
C atexit function has the following syntax.
int atexit(void (*func)(void));
Header
C atexit function
is from header file stdlib.h
.
Description
C atexit function causes the function pointed to by func to be called upon normal program termination.
C atexit function returns zero if the function is successfully registered as a termination function and nonzero otherwise.
At least 32 termination functions can be registered, and they will be called in the reverse order of their registration.
Example
Use C atexit function to call a function when exiting normally.
#include <stdlib.h>
#include <stdio.h>
/*from ww w . j a v a 2 s.co m*/
void done(void);
int main(void)
{
if(atexit(done)){
printf("Error in atexit().");
}
return 0;
}
void done(void)
{
printf("Hello There");
}
The code above generates the following result.