Jump to content
  • Advertisement
Sign in to follow this  
lubricatedGoat

I'm so stupid, I need help .

This topic is 5409 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

I'm attempting to program in C and I've tried the Borland and Dev C++ compiler. Whenever I try to make the first program that just displays a message in a window that quickly appears and disappears before I can begin reading the message. It happens in both and with programs that are just meant to print something from different references. I'm stupid, just please tell me what I'm doing wrong :(. I am doing a .C file and the window is a DOS one with Dev C++ and I can't see it long enough to make out any of it with Borland. Thanks

Share this post


Link to post
Share on other sites
Advertisement
The problem is that once the program finishes Windows kills the console window, so either run the program from the command prompt by opening a console in windows (start->run->cmd) and then typing the name of your exe, or add a line to take some user input like getch() or cin.ignore(), which will pause the program until you push a key.

Share this post


Link to post
Share on other sites
What's happenning is that Windows is detecting that the program has finished executing so it automagically closes the DOS window for you. To get around this, just before your program terminates have the user press a key. For example, place this function before your main() function:

void WaitForKey(void)
{
char key;
printf("Press any key.....");
scanf("%c",&key);
}


and then at the end of main() call it. This will force the program to wait until the user presses a key before terminating (and closing the DOS window)

Share this post


Link to post
Share on other sites
another thing you could do is just put a while(1) loop in it or a system("pause") function call that will also pause your system
(and im regardes to being stupid every one had to start some were) Good Luck

Share this post


Link to post
Share on other sites
Quote:
Original post by raptorstrike
another thing you could do is just put a while(1) loop

Don't do this!!! This will send your program into an infinite loop and the program wont be able to terminate 'normally'. Sure, it might be fine as a quick hack to get what you want but it's much better to learn how to do it properly.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!