As people have mentioned, this doesn't make sense for ANSI C. For Windows, you'll need to be more specific about what you want.
If you're writing a console application (done automatically if you're using main
, or if you explicitly pass the /SUBSYSTEM:CONSOLE
flag to the linker), you don't need to do anything special. Running your application from a windowed application will spawn a console window for you. Running it from an existing console window will reuse that one.
If you're writing a windowed application (done automatically if you're using WinMain
, or if you explicitly pass the /SUBSYSTEM:WINDOWS
flag to the linker), you can use AllocConsole
. See the Creation of a Console article from MSDN. (I think you also should be able to do that if you're writing a console application and never want to reuse an existing console, but I'd have to say that doing so would be very user-unfriendly.)