How to use exit in C

This is a discussion on How to use exit in C within the C Programming forums, part of the General Programming Boards category; Hi... I'm doing a simple program in C, and i need a option that terminates the program. For example, instead ...

  1. #1
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194

    How to use exit in C

    Hi...

    I'm doing a simple program in C, and i need a option that terminates the program.
    For example, instead of appearing "Press any key to continue..." the program will instantly close.
    I've been googling and i found some references on a exit command, but i don't have any ideia on how to use it :-S

    Can anyone help me??

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Google is amazing. Here's a random site that talks about the exit function:

    http://www.phim.unibe.ch/comp_doc/c_...IONS/exit.html

    The integer that exit() takes as an argument is the return value that you want to send to the calling application. Its usage outside of main() should generally be restricted to fatal errors that your program has no way of gracefully handling. I believe all normally working applications should exit by allowing the flow of the program to finish in main() if possible.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I'm doing a simple program in C, and i need a option that terminates the program.
    For example, instead of appearing "Press any key to continue..." the program will instantly close.
    I take it that you're running the program from MSVC and you want it to exit immediately? In that case, you'll have to run the program from the command prompt or something. I think MSVC will print "Press any key to continue" no matter what.
    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. Chat Program Help?
    By Paul22000 in forum Networking/Device Communication
    Replies: 9
    Last Post: 02-09-2009, 11:35 PM
  2. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  3. Replies: 1
    Last Post: 03-21-2006, 06:52 AM
  4. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. exit() ?
    By smd in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2002, 04:31 PM

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