How to use atexit() to call a function on normal program termination in C

2 Answers

0 votes
#include <stdlib.h>
#include <stdio.h>
 
void f1()
{
    puts("run f1()");
}
 

int main(void)
{
    atexit(f1);
}
  


/*
run:
 
run f1()

*/

 



answered Aug 25, 2016 by avibootz
edited Feb 27, 2022 by avibootz
0 votes
#include <stdlib.h>
#include <stdio.h>
 
void f1()
{
    puts("run f1()");
}
void f2()
{
    puts("run f2()");
}

int main(void)
{
    atexit(f1);
    atexit(f2);
}
  


/*
run:
 
run f2()
run f1()

*/

 



answered Aug 25, 2016 by avibootz
edited Feb 27, 2022 by avibootz
...