c - Why does my program's output flash and close in Windows? -


I & amp; I'm trying to create an .exe file for "hello, world". The code given in the book is:

  #include & lt; Stdio.h & gt; Main () {printf ("hello, world! \ N"); }  

When I & amp; To run from Code :: Blocks (under Windows XP), I get a quick window with the message "Hello World" until I manually turn it off until it remains open. However, when I double click on the .exe file, the signal only shines and disappears, why is it so?

Nobody is telling you this clearly, so I will:

< P> When you double click General

Why is it like this?

What your IDE does (to keep the window open) is an feature .

Since you are developing the console application, your app should have a console to display its output. If no one is yet, a new console has been created (which is a black window).

If you launch your program from inside the console (say, from cmd.exe ), this will inherit only the parents' console to be new [1] ].

After the last application using the console exit (which is just your program in the first case), the console stops. You will pay attention to the console applications all the time, while not running anything without the help of parameters, but print the help text if you double-click them from Explorer, a black window with some text will flash and close immediately Will go.

  • Occasionally, any program that does and immediately closes is what you want. For example, you can call these applications with scripts.

  • On the other hand, your application may be interactive: the user is waiting for input, doing something and only when the user exits is asking you to do these applications. The script can not be, obviously, as you have to tell the application what to do, you have to be present to be a human.

Now we go to the IDE section: Suppose you are developing the first type of application, whatever works and then immediately closes. This screen is not very easy to flash and every time you run it, how can you tell that what the program works? Let's say you can tell it from the output that it is producing.

You can of course start a command line window and run the application from there, but the program will be executed separately from IDE, and you will lose live debugging capabilities

Therefore, the IDE Creator console comes with a feature for applications: When you run the application directly from your IDE, they later wait for a keypress, usually with the output Gives the opportunity to inspect the window, to confirm that the app is working properly.


[1] Asterikika: As long as you go through an application that does not deprive the console, any console app launched by that app will not get the heir of the console, Because the legacy was broken by GUI app. For example, start.exe does this comparison:

  foo.exe (processes the console) start foo.exe (start.exe a GUI app, so foo.exe is launched in a new console)  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -