exit Function

Terminates program after clean up.

Include

<stdlib.h>

Prototype

void exit(int status);

Argument

status
exit status

Remarks

exit calls any functions registered by atexit in reverse order of registration, flushes buffers, closes stream, closes any temporary files created with tmpfile and resets the processor. This function is customizable. See pic30-libs.

Example

#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