How to exit the program?

This is a discussion on How to exit the program? within the C++ Programming forums, part of the General Programming Boards category; Please, is there any function to exit the program?...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    5

    Unhappy How to exit the program?

    Please,
    is there any function to exit the program?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    No. You can never exit(0) a program, once you start it, you'll have to power off your PC to stop it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    5
    realy?
    I mean to exit the program just like the
    die in perl.
    Of cause I can use Ctrl+C to stop but I
    want the program stop itself.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    You can use the exit() function, but you shouldnt have a need to use it and it is often deemed bad practice....

    To exit you should allow the the code to reach the end of the main() function and let it end naturally

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    I doubt you can exit a program with ctrl-C either...
    It's debatable whether using exit(int i) is bad practice. Sometimes you need to get out of a program fast, and letting it come to an end isn't really an option.
    Be sure to delete any allocated memory along with the exit() function though, or stuff will most probably crash, or discard a memory, which might not seem so bad, but if you start and exit the program 100 times, your system resources will start to deplete, especially if your program loads big fat files.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP with Program!
    By afnitti in forum C Programming
    Replies: 9
    Last Post: 04-15-2009, 09:06 PM
  2. exit a program at any point.
    By slightofhand in forum C Programming
    Replies: 5
    Last Post: 03-02-2008, 09:08 AM
  3. Program Terminating With Error On Exit
    By chriscolden in forum C Programming
    Replies: 19
    Last Post: 01-14-2006, 04:40 AM
  4. Program uses a lot of memory and doesnt exit properly
    By TJJ in forum Windows Programming
    Replies: 13
    Last Post: 04-28-2004, 04:13 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21