This shows you the differences between two versions of the page.
c:stdlib.h:atexit [2013/01/22 22:02] |
c:stdlib.h:atexit [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== atexit ====== | ||
+ | |||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | int atexit(void (*func)(void)); | ||
+ | </code> | ||
+ | ===== Description ===== | ||
+ | <code c> | ||
+ | The atexit function registers the given function to be called at normal | ||
+ | process termination | ||
+ | |||
+ | atexit returns the value 0 if successful, otherwise it returns | ||
+ | a nonzero value. | ||
+ | </code> | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <stdlib.h> | ||
+ | |||
+ | void ExitMessage( void ) | ||
+ | { | ||
+ | printf("atexit was called, this is the exit message\n"); | ||
+ | } | ||
+ | |||
+ | int main( void ) | ||
+ | { | ||
+ | atexit(ExitMessage); | ||
+ | |||
+ | printf("The ExitMessage will shown after this line\n"); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | user@host:~/code-reference.com# ./atexit | ||
+ | The ExitMessage will shown after this line | ||
+ | atexit was called, this is the exit message | ||
+ | |||
+ | |||
+ | |||