I'm so stupid, I need help .

Started by
4 comments, last by joanusdmentia 19 years, 7 months ago
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
ownage with style
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.
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)
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
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!
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.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement