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 value description EXIT_SUCCESS 0 Normal termination EXIT_FAILURE 1 Abnormal 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;
}