Thread: how to use atexit()??

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    17

    Question how to use atexit()??

    the description of at exit is as follows, can somone give me an example of how it is used??

    int atexit( void (*func)(void) );
    Parinoia Means Having All The Facts!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The atexit function will call a chosen function at the end of a program, the nice thing about this function is that it will call something useful such as garbage collection and saving routines even if you abort by way of exit().
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void end( void )
    { 
      printf ( "The end function was called\n" ); 
    }
            
    int main ( void )
    {
      atexit ( end );
      printf ( "Normal processing\n" );
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. atexit
    By lolguy in forum C Programming
    Replies: 8
    Last Post: 01-16-2009, 06:30 PM
  2. atexit function
    By strokebow in forum C Programming
    Replies: 2
    Last Post: 11-24-2006, 04:45 PM
  3. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  4. atexit not running?
    By ichijoji in forum C++ Programming
    Replies: 4
    Last Post: 08-05-2005, 03:28 PM