Close console window in C

4

I need to create the old woman's game. I want to know how to close the black little window that appears without needing to click any key, for example: When you run the program it appears:

  

1 to play

     

0 to exit

If the user types 0, I want the program to shut down completely without having to hit Enter.

    
asked by anonymous 15.06.2016 / 23:36

1 answer

4

According to an OS question :

  

The console (or shell) the program is running on is completely independent of its program, it is just a user interface (I / O). Trying to close the console is not a good idea - instead you should start your program without tying it. (this is easy in the Unix environment, but harder in Windows)

On Unix you should look at the command kill(2) .
Under Windows you have to run a command killing the process by its name: system("taskkill /IM cb_console_runner.exe") .

    
16.06.2016 / 02:05