6.19.5 _Exit function
Description
Terminates program execution.
Include
<stdlib.h>
Prototype
void _Exit(int status);
Argument
status
- exit status
Remarks
When using MPLAB XC8 for PIC, the _Exit
function causes process
execution to halt in an endless loop without calling any functions registered by
atexit
.
For all other compilers, the _Exit
function resets the processor without
calling any functions registered by atexit
. This function is
customizable.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *myfile;
if ((myfile = fopen("samp.fil", "r" )) == NULL)
{
printf("Cannot open samp.fil\n");
_Exit(EXIT_FAILURE);
}
else
{
printf("Success opening samp.fil\n");
_Exit(EXIT_SUCCESS);
}
printf("This will not be printed");
}
Example Output
Cannot open samp.fil