any command to end a program in C?
-
- Mental DCEmu
- Posts: 304
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Mon Sep 01, 2003 4:57 pm
- Has thanked: 0
- Been thanked: 0
any command to end a program in C?
Ok, I come to this problem a lot, and I don't know how I can actually efficiently program in C without this knowledge: is there a command to halt the program and end it right where it is? The program I just recoded uses a lot of loops that I can't just use break; with. and they're embedded in if statements to make them even harder to stop. the only way to do this would be to use an exit function of some sort, like basic's exit command... It's driving me pretty nutty, and I cant even find a command like this in C the Complete reference third edition (and that's a pretty extensive book).
thanks Sanchez. I relly dont care if its the right way to do it, as long as it doesnt let you continue the game (thats what I'm making) after you die... it doesnt registers that your characters dead (i mean the functions that say your dead works) but you can keep playing if you dont mind the "your dead" message... :p thanks a lot.
-
- Insane DCEmu
- Posts: 190
- Joined: Sun Jun 27, 2004 8:35 pm
- Location: stillwater, ok
- Has thanked: 0
- Been thanked: 0
- Contact:
-
- Insane DCEmu
- Posts: 190
- Joined: Sun Jun 27, 2004 8:35 pm
- Location: stillwater, ok
- Has thanked: 0
- Been thanked: 0
- Contact:
oh yeah, duh. one should write a custome program ending function then call exit. also, some OS'es will automatically cleanup any allocated memory for the program when terminated (like Win32, most DOS apps, Mac OS, etc.... dunno how it works in the console world, i assume exit() would not ever be a thing to call anywaysSanchez wrote:What I mean is exiting like he's doing in the middle of a loop is not clean, especially if resources have been malloc'd, etc...
- SinisterTengu
- DC Developer
- Posts: 382
- Joined: Wed Oct 17, 2001 7:44 pm
- Location: Arlington, WA
- Has thanked: 0
- Been thanked: 0
you could also just make your loops dependant on that the character is not dead..
Then when your character does die, it will exit whatever loops are dependant, and you will get past those loops to where you can clean up and exit nicely.
Code: Select all
while(dead == false) {
...
}
- toastman
- Iron Fist of Justice
- Posts: 4933
- Joined: Sat Nov 10, 2001 3:08 am
- Location: New Orleans
- Has thanked: 0
- Been thanked: 0
- Contact:
Never depend on system behavior to do something you should take care of yourself.Rev. Layle wrote:oh yeah, duh. one should write a custome program ending function then call exit. also, some OS'es will automatically cleanup any allocated memory for the program when terminated (like Win32, most DOS apps, Mac OS, etc.... dunno how it works in the console world, i assume exit() would not ever be a thing to call anywaysSanchez wrote:What I mean is exiting like he's doing in the middle of a loop is not clean, especially if resources have been malloc'd, etc...
No signature.