help: how do i terminate a program

This is a discussion on help: how do i terminate a program within the C++ Programming forums, part of the General Programming Boards category; how do i terminate a program in the middle of it with out any error messages?.......

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    1

    Question help: how do i terminate a program

    how do i terminate a program in the middle of it with out any error messages?....

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    exit(0)?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    That's the one; but sometimes that is a bad idea. Why would you be doing this termination?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    return 1.

  5. #5
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59

    That's the one; but sometimes that is a bad idea. Why would you be doing this termination?
    and why would this be a bad idea ? isnt the purpose of the exit() function to cause immediate normal termination of a program ? just wondering

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Quote Originally Posted by indigo0086
    return 1.
    That only returns from the currently executing function--it does not terminate the program. Additionally, you would typically return 0 when there are no errors, just like in main():
    Code:
    int main()
    {
         //code
        
        return 0;
    }

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,439
    Quote Originally Posted by C of Green
    and why would this be a bad idea ? isnt the purpose of the exit() function to cause immediate normal termination of a program ? just wondering
    Several reasons:

    - Calling exit will not give the caller a chance to deal with the problem. Exceptions are better.
    - Calling from inside an object destructor may originate an infinite recursion.
    - Calling exit does not guarantee all resources get released. Namely, local variables of the calling function will not have their destructors called.

    Quote Originally Posted by indigo086
    return 1.
    return does not terminate a process unless from within main. Also, the argument value 1 will indicate an error.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    oh...

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    Program designs vary widely, but in general, when a program exits without error, it is because main()'s return was reached logically. If there's an error that can be resolved only by program termination, then throw an exception and, should you find the problem truly is unresolvable at every level of calling, the program will be terminated.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Need Delimiter Program helpful hints.
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 02-16-2002, 05:27 PM
  4. 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