Thread: exiting program

  1. #1
    Registered User
    Join Date
    Mar 2006

    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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Just call the exit() function if you want to bail out from the whole program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    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():
    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;

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Program exiting
    By sql.scripter in forum C Programming
    Replies: 9
    Last Post: 01-28-2006, 08:51 PM
  4. Exiting a program
    By osal in forum Windows Programming
    Replies: 2
    Last Post: 07-14-2004, 08:51 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM