-
exiting program
in the program i am doing i need to give the option to the user for exiting the program totally at certain points in the game, i was wondering if anybody could help me out with writing the code for it. The program is containing a lot of for and while loops. thanks in advance for helping
-
Just call the exit() function if you want to bail out from the whole program.
-
If you're in main() you can use return x. If you're in a function other than main() you can return a value up the stack to main():
Code:
int main(void) {
/* ... */
if(one()) return 1;
/* ... */
}
int one(void) {
/* ... */
if(two) return 1;
/* ... */
return 0;
}
int two(void) {
/* ... */
if(error) return 1;
/* ... */
return 0;
}