You are watching: How to end a program in c
Is there any kind of immediate means to end the whole program without gift in main?
The standard function exit is what you room looking for:
Terminates the procedure normally, performing the regular cleanup for terminating processes.
First, all functions registered by calls come atexit space executed in the reverse order of their registration. Then, every streams are closed and the temporary records deleted, and finally the control is returned to the host environment.
The status discussion is went back to the host environment.
It would be far better though if you resolved the segfault error.
You need to incorporate the traditional lib and then girlfriend can contact exit wherever you want:
#include ...exit(status);where status is an integer representing the exit code.For what worry status: because that the convention 0 is success, other values shows an error status.
You can likewise fprintf(stderr, ....) and also then call abort(); this deserve to be beneficial if you desire to debug later on your bug.
But I think you should recode your regimen so the size constraints are only provided by available resources: therefore if you run your regime on a much bigger computer (whatever that means) it can process an ext than 100 inputs.
A slightly far better thing to do might be to capture the segment fault with a signal handler, and have the signal handler progressive a SIGSTOP signal.
That means your routine stops, but stays in memory. You can then connect to it v a debugger and also see the regime in all its glory frozen in location at the suggest the SEGFAULT happened.
That deserve to be helpful for finding troubles in lengthy running programs the you aren"t running inside a advance IDE.
Thanks for contributing an answer to ridge Overflow!Please be sure to answer the question. Carry out details and share your research!
But avoid …Asking because that help, clarification, or responding to other answers.Making statements based upon opinion; ago them up with recommendations or an individual experience.
See more: When Did Martin Truex Jr Get Married, Martin Truex Jr
To find out more, watch our advice on writing great answers.
article Your prize Discard
Not the price you're spring for? Browse other questions tagged c departure or questioning your very own question.
site design / logo design © 2021 stack Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.9.21.40262