[C] function to exit the console?

popoff -  
 sohaib -
Good evening,

I'm just looking for the function that closes the console at the end of a program. Something like system("PAUSE"); (which pauses the program) but that closes the console. Thanks.

Configuration: Windows Vista Firefox 2.0.0.11

8 answers

  1. fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
     
    I don’t quite understand what you mean. But test:
    system("exit");

    Otherwise, when you run your program, there is no need to close the window since it closes on its own at the end of the program. (Unless you launch from the console, but in that case it will annoy the user if it closes).
    So the cleanest is simply to quit the program with a simple: return 0;
    Best regards
    --

    Google is your friend
    10
    1. sohaib
       
      Thank you very much
      0
  2. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    It is necessary to kill cmd.exe with a taskkill.
    3
  3. Char Snipeur Posted messages 10112 Registration date   Status Contributor Last intervention   1 331
     
    I don’t understand what you want to do. I think it’s impossible.
    tell us the exact behavior you expect and what you want to do.
    --

    Salutation ! When we don’t know, we don’t touch!JBT
    Char Snipeur
    2
  4. RoMz34
     
    Sorry to bump this old topic, but better not to recreate one ^^, I have the same problem as the person who posted it. In a party, he tries to program in C (from what I understood), and in his code he is looking for a system that allows quitting the console automatically. He took as an example system("PAUSE") which lets the program pause.

    I have the same problem as him; indeed, I’m a beginner, I started yesterday, I’m following a tutorial to help me program, and the first TP consists of creating a +/- , my problem being, in the menu I’d like to have the option to start or quit ... I don’t know the command that allows closing the console <system ...=""> <=== there you go ^^ it’s not clearer, if someone could help ... :s</system>
    2
  5. RoMz34
     
    thank you ^^ system("exit") doesn’t work, but in the end, I just needed a method to go to the end of the program, or to finish the program => return 0; SIMPLY thank youuuuuuuuuu ^^, I’m sorry, I started yesterday so, it’s not all this easy for me yet!
    2
  6. SebManfred Posted messages 484 Registration date   Status Member Last intervention   128
     
    exit
    1
  7. earth
     
    Hello,

    I just tested with a "return 0" at the end of my program, but the console still stays open :(
    1
    1. fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
       
      Please open your own post...
      0
  8. Mr.Chuckchucky
     
    exit(0);
    Anyway, that's the answer in C++
    -1
    1. fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
       
      8 years later :-).
      That does not close the console...
      That terminates the program with exit code 0.
      By the way, when you exit with code 0, it often comes from main(). And we’ll use return 0; instead. To quit a program in case of an error, it’s more like exit(EXIT_FAILURE); which we’ll use.
      0