exit
void  exit ( int status );
stdlib.h
  cplusplus.com  

Terminate calling process.
  The process performs standard cleanup and then terminates. Before the cleanup is done any function registered by atexit is called. The cleanup consists on flushing all buffers and close any open files.
  The status parameter is returned to the parent of the process (if any) or the operating system as if a return statement was specified in main function. Generally a return value of 0 or constant EXIT_SUCCESS indicates success and any other value or constant EXIT_FAILURE is used to inidcate an error or an abnormal program termination.

Parameters.

status
status value returned to parent process (if any) or operating system, generally:
statusvaluedescription
EXIT_SUCCESS0Normal termination
EXIT_FAILURE1Abnormal termination. Error in process.

Return Value.
  (none)

Portability.
  Defined in ANSI-C.

Example.

/* exit example */
#include <stdio.h>
#include <stdlib.h>

main ()
{
  FILE * pFile;
  pFile = open ("myfile.txt","r");
  if (pFile==NULL)
  {
    printf ("Error opening file");
    exit (1);
  }
  else
  {
    /* file operations here */
  }
  return 0;
}

See also.
  abort, atexit


© The C++ Resources Network, 2000