Stopping a program

This is a discussion on Stopping a program within the C Programming forums, part of the General Programming Boards category; Is there any command I can use to stop my program? I would usually just stick a return 0; in ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    174

    Stopping a program

    Is there any command I can use to stop my program? I would usually just stick a return 0; in but this time I want it to stop the program from within another function besides main.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    5,846
    Look up the exit() function, declared in <stdlib.h>.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    174
    I'm not allowed to do that, so I guess I'm going to have to find another approach to my problem. I'll be back if I get stuck again.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    5,846
    I assume, if you are not allowed to use exit(), you are also not allowed to use abort() or assert().

    The only other option - at least, within bounds of standard C - is to all design your functions so, when you need to exit, all called functions back out until control returns to main().
    Right 98% of the time, and don't care about the other 3%.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    You could also continue to return 0 (as an example) from your function to indicate an error, then handle it in the function making the call by checking the return value. Like alot of functions in the standard library does.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stopping further program execution.
    By darren78 in forum C# Programming
    Replies: 3
    Last Post: 09-29-2010, 05:42 AM
  2. Program stopping working
    By SterlingM in forum C++ Programming
    Replies: 24
    Last Post: 10-17-2009, 02:38 PM
  3. Stopping a program from running?
    By Daniel in forum Windows Programming
    Replies: 4
    Last Post: 03-12-2003, 01:04 AM
  4. stopping a program
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-27-2002, 11:28 AM
  5. One error stopping me run program.
    By andy bee in forum C Programming
    Replies: 1
    Last Post: 08-28-2001, 06:57 PM

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