### exit -- End Program

Format

>     #include <stdlib.h>  /* also in <process.h> OS/2 only*/
>     void exit(int status);

Language Level: ANSI, POSIX, XPG4, Extension
exit returns control to the host environment from the program. It first calls all functions registered with the atexit function, in reverse order; that is, the last one registered is the first one called. See atexit -- Record Program Termination Function for more information. It flushes all buffers and closes all open files before ending the program. All files opened with tmpfile are deleted.

The argument status can have a value from 0 to 255 inclusive or be one of the macros EXIT_SUCCESS or EXIT_FAILURE. A status value of EXIT_SUCCESS or 0 indicates a normal exit; otherwise, another status value is returned.

Return Value
exit returns both control and the value of status to the operating system.

Example
This example ends the program after flushing buffers and closing any open files if it cannot open the file myfile.mjq.

    #include <stdio.h>
    #include <stdlib.h>

    #define FILENAME "myfile.mjq"

    FILE *stream;

    int main(void)
    {
       if ((stream = fopen("FILENAME", "r")) == NULL)
       {
          perror("Could not open data file");
          exit(EXIT_FAILURE);
       }
       return 0;

       /*******************************************************
          The output should be:

          Could not open data file: The file cannot be found.
       /******************************************************/
    }

abort -- Stop a Program
%22">atexit -- Record Program Termination Function
_onexit -- Record Termination Function
_exit -- End Process
signal -- Handle Interrupt Signals
tmpfile -- Create Temporary File
<stdlib.h>