How can I immediately close a program in C?

You need to include the standard lib and then you can call exit wherever you want:

#include <stdlib.h>
...
exit(status);

where status is an integer representing the exit code. For what concern status: for the convention 0 is success, other values indicates an error status.


The standard function exit is what you are looking for:

Terminates the process normally, performing the regular cleanup for terminating processes.

First, all functions registered by calls to atexit are executed in the reverse order of their registration. Then, all streams are closed and the temporary files deleted, and finally the control is returned to the host environment.

The status argument is returned to the host environment.

It would be better though if you fixed the segfault error.

Tags:

C

Exit