I'm so stupid, I need help .
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
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.
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:
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)
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)
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
(and im regardes to being stupid every one had to start some were) Good Luck
It sounds like you're trying to run your program by double-clicking on it from explorer. Try running it from the command prompt instead.
Edit: too slow!
Edit: too slow!
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement