Thread: help: how do i terminate a program

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    exit(0)?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    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,663
    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
    Ireland
    Posts
    8,446
    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.
    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
    937
    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, 11: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, 06:27 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM