![]() |
|
#1
|
|||
|
|||
How to use exit in CHi, i'm doing a simple program in C, and i need a option that terminates the program.
For example, instead of appearing "Press any key to continue..." the program will instantly close. I've been googling and i found some references on a exit command, but i don't have any ideia on how to use it :-S Can anyone help me?? |
|||
|
#2
|
|||
|
|||
Re: How to use exit in CQuote:
Don't put system("pause"); in the program, since that is what causes the message to appear and causes it to wait for a keypress. A "normal" program termination is a return from main() CPP / C++ / C Code:
If you are way down in some nested calls of functions and you want to "exit" immediately, without returning all of the way to main(), then use exit: CPP / C++ / C Code:
Look up standard library functions at places like this: Standard C Library. Click on <stdlib.h> and scroll down to exit Regards, Dave |
|
#3
|
|||
|
|||
Re: How to use exit in CHi Dave, thanks for the reply
Ok, now i understand how to exit a program without the "Press any key to continue...". What is the best option to exit a program, when you are using files and lot's of functions? Is it the exit(EXIT_SUCCESS); or exit(EXIT_FAILURE); ? |
|
#4
|
|||
|
|||
Re: How to use exit in CQuote:
The actual mechanism for returning a value is not part of the C language (it's operating-system dependent). The only two values defined in Standard C are the EXIT_SUCCESS, or EXIT_FAILURE macros in <stdlib.h>. That is, "exit(3)", for example, may cause different actions, depending on the operating system. The statement "exit(EXIT_SUCCESS)" is equivalent to exit(0). The result of an "exit(0)" is the same as a "return 0;" at the end of main(). Typically people use "return(0)" or "exit(0)" or "exit(EXIT_SUCCESS)" unless they want to give the calling program to discriminate between a satisfactory termination and termination caused by an error condition. Regards, Dave |
|
#5
|
|||
|
|||
Re: How to use exit in CHey!
Once again, thanks for the reply. It was clear as water Regards, IndioDoido |
Recent GIDBlog
Running Linux Programs at Boot Time by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please Help Me To Build My Calendar!!! | suriacute85 | Java Forum | 0 | 05-Oct-2006 19:39 |
| functions seems not to exit from a certain code block | jaro | C Programming Language | 3 | 21-Mar-2006 23:08 |
| When to use exit() Instead of return? | BobbyMurcerFan | C Programming Language | 10 | 24-Nov-2004 23:44 |
| child pid xxx exit signal Segmentation fault (11) | bezak | Apache Web Server Forum | 1 | 24-Nov-2003 09:18 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The