Terminates a program normally.
#include <stdlib.h> void exit(int status);
status
The exit error value.
The exit() function calls every function installed with atexit() in the reverse order of their installation, flushes the buffers and closes all open streams, then returns to the operating system with the value in status.
#include <stdio.h> #include <stdlib.h> int main(void) { FILE *f; int count; /* Create a new file for output, exit on failure. */ if (( f = fopen("foofoo", "w")) == NULL) { printf("Can't create file.\n"); exit(1); } /* Output numbers 0 to 9. */ for (count = 0; count < 10; count++) fprintf(f, "%5d", count); /* Close the file. */ fclose(f); return 0; }