开发者

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");

should do the trick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜