

#include <stdlib.h> void exit(int code);
exit terminates the program after closing all files. The integer
argument code is used in an implementation-defined way to indicate
the results of execution. Usually, a code of EXIT_SUCCESS
indicates successful execution, and a code of EXIT_FAILURE
indicates an unsuccessful execution.
exit.
exit if memory management
data areas have been overlaid.
exit is generally portable, although any meaning associated with
the code argument is not. Some systems only treat the last 8 bits
of the code as significant, so codes from 0 to 255 are recommended
for maximum portability.
Many C implementations also support a routine named _exit to
terminate execution without closing files. This routine is available
only when OpenEdition under MVS is installed.
exit is implemented as a longjmp to a target defined in the
library routine that calls main. Therefore, it can be intercepted
with blkjmp.
On IBM's 370 system, EXIT_SUCCESS is 0 and EXIT_FAILURE is 16. The
exit code is used as an MVS or CMS return code. Under MVS, a code that
is not between 0 and 4095 is changed to 4095.
#include <stdlib.h>
#include <stdio.h>
main(int argc, char *argv[])
{
FILE *f;
if (argc > 1){
f = fopen(argv[1],"r");
if (f == NULL){
fprintf(stderr,
"Can't open file "%s"n", argv[1]);
exit(EXIT_FAILURE);
}
fclose(f);
puts("File successfully opened and closed.");
exit(EXIT_SUCCESS);
}
else{
fprintf(stderr,"No file specified.n");
exit(EXIT_FAILURE);
}
}
abort, atexit, blkjmp, coexit, _exit
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.