Jump to content
  • Advertisement
Sign in to follow this  
calitriuk

Help Me Please!!!

This topic is 4409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am a complete newbie to programming so im starting with c and then im going to work my way up, i have a compiler (Dev-c++) and a few tutorials im learning but im having a problem im running windows xp and when i write the program and compile and run it the window closes down before i can even see anything what am i doing wrong? its driving me mad there is a help area with the program that says what u should do but this just brings up errors if any1 can help it would be much apricatied,!

Share this post


Link to post
Share on other sites
Advertisement
That is the normal behaviour for a console application. They are designed to be run from a command prompt, in which case their output stays on the screen, but when you run them from within Windows, a new console is created to run your application which exits when the application has terminated.

Before you are innundated with suggestions to put system("pause"); as the last line of your program (which will technically work) let me suggest some better solutions:

1) If your IDE supports it, set a breakpoint at the end of your program. This removes the artificial "wait for a keypress" from your program, which you only want there while developing, and moves it into the development environment.

2) Run your program from a command prompt rather than from the IDE. Please feel free to post if you need more information on this.

3) Create a batch file containing:

c:\whatever\my_program.exe
pause

and run your program by double-clicking this file. This again removes the pause from your program itself.

4) If you must put the pause in your program, rather than use the non-standard system("pause"); consider using:

std::cin.get(); // this is standard C++ but will be "fooled" on occasion by other input still in the stream

or see if your compiler has an include file <conio.h> and a function getch(); which will actually physically wait for a keypress.

system("pause"); at the end is an okay-ish solution if you are just beginning but you need to be aware that it is not a good long-term solution. There is a lot to be said for using a command prompt not just for running console apps but for developing them as well, although that does deny you the advantages of an IDE and debugger. Also, if some unscrupulous person was to put a program called "pause.exe" in the same directory as your program, that would be run instead of the system pause command, with all the security implications that brings.

Share this post


Link to post
Share on other sites
It's supposed to behave this way. Just run your program through the command line. That way the console window will not close when your program terminates.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!