Use of exit() function
Try man exit.
Oh, and:
#include <stdlib.h>
int main(void) {
/* ... */
if (error_occured) {
return (EXIT_FAILURE);
}
/* ... */
return (EXIT_SUCCESS);
}
Try using exit(0);
instead. The exit
function expects an integer parameter. And don't forget to #include <stdlib.h>
.
The exit
function is declared in the stdlib header, so you need to have
#include <stdlib.h>
at the top of your program to be able to use exit
.
Note also that exit
takes an integer argument, so you can't call it like exit()
, you have to call as exit(0)
or exit(42)
. 0 usually means your program completed successfully, and nonzero values are used as error codes.
There are also predefined macros EXIT_SUCCESS
and EXIT_FAILURE
, e.g. exit(EXIT_SUCCESS);