Close console window in C

Asked

Viewed 1,139 times

5

I need to create the old game. I want to know how to close the black window that appears without having to click any key, for example: When running the program appears:

1 to play

0 to leave

If the user type 0 I want the program to close completely without having to click Enter.

1 answer

5

According to an OS question:

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

In Unix you should look over the command kill(2).
In Windows you need to execute a kill command by killing the process by its name: system("taskkill /IM cb_console_runner.exe").

Browser other questions tagged

You are not signed in. Login or sign up in order to post.