exiting program

This is a discussion on exiting program within the C Programming forums, part of the General Programming Boards category; in the program i am doing i need to give the option to the user for exiting the program totally ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    22

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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;
    }
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    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, 06:49 PM
  3. Program exiting
    By sql.scripter in forum C Programming
    Replies: 9
    Last Post: 01-28-2006, 07: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

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