简体   繁体   中英

how to open new console window using Ansi C?

i am beginner in Anci c programming here is the description for my program my program first asks user to press any key then a new console is opened and the user inputs any number he want then the console is closed and the number he typed is printed in the parent console ,i hope this clear and thanks for reply

so i want the function that opens a new console i am using Code::Blocks gcc compiler under win 7

"ANSI C" doesn't know there is such a thing as "consoles" or "windows". This is almost certainly going to depend on the operating system and/or windowing environment being used, as well as any third-party libraries being used to drive these kinds of operations. Maybe something like ncurses would be helpful here, but there's no way of knowing without more specific information.

ANSI C doesn't have a concept of "windows". That's an operating system concept outside the area of the C language.

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.)

system("cmd");

应该可以

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM