[ Programing ]/C++
atexit() 로 종료 전 동작을 예약하자.
Mister_Q
2010. 1. 31. 07:09
atexit() 로 종료 전 동작을 예약하자.
atexit()
설명 : 프로그램이 끝났을 때 호출 될 function을 등록한다. 등록된 함수는 등록된 반대 순서로 호출된다.
반환 : 성공시 0, 실패시 -1
#include <stdio.h>
#include <unistd.h>
void hkpco()
{
printf("print hkpco...\n");
}
void use_atexit()
{
printf("using.. atexit function...\n");
}
int main()
{
int integer;
integer = 0;
atexit( use_atexit );
printf( "atexit called!!!\n" );
hkpco();
sleep( 2 );
printf( "This is atexit program!\n" );
printf( "integer : " );
//scanf( "%d" , &integer );
printf( "You -> input -> %d\n" , integer );
printf( "soon program exit!\n" );
sleep( 1 );
printf( "bye~\n");
exit( 0 );
}
출력 :
atexit called!!! print hkpco... This is atexit program! integer : You -> input -> 0 soon program exit! bye~ using.. atexit function...
출저 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/3/atexit