Call atexit() function to register function - C Function

C examples for Function:Utility Function

Description

Call atexit() function to register function

Demo Code

#include <stdio.h>
#include <stdlib.h>
void sign_off(void);
void too_bad(void);

int main(void){
    int n;/*from ww  w  .  ja v a  2  s . c  o m*/
    
    atexit(sign_off);    /* register the sign_off() function */
    
    puts("Enter an integer:");
    
    if (scanf("%d",&n) != 1){
        puts("That's no integer!");
        atexit(too_bad); /* register the too_bad()  function */
        exit(EXIT_FAILURE);
    }
    printf("%d is %s.\n", n,  (n % 2 == 0)? "even" : "odd");
    
    return 0;
}

void sign_off(void){
    puts("terminates program from sign_off");
    puts("hi!");
}

void too_bad(void)
{
    puts("hi ");
    puts("test.");
}

Related Tutorials