View Full Version : C Puase Question
When you run a program in C such as in Visual Basic, what is the information to input to keep the program active? Such as when you run the program you made and when it runs it runs instantly and then automatically quits out. I need to make it so that it stays up.
Such as in the HELLO WORLD beginners program, what is the command that keeps it up instead of closing instantly?
Isn't it ;PUASE or something?
a2jfreak
29 Sep 2003, 8:08pm
pause isn't built in, but you can make your own, or you can just put an infinite loop @ the end to make it stay up.
Infinite loop would be the quickest (and dirtiest) way to make it stay up if it's a piddly program like Hello world.
for(;;);
while(1);
take your pick.
a2jfreak
29 Sep 2003, 8:26pm
Ok, then write your own because I don't know of one built into the MSVC++ libraries.
#include < time.h >
void pause(unsigned int t)
{
int x = clock();
for (int x = clock(); clock() - x >= t;);
}
Then just use pause(5000); for a pause of ~5 seconds.
To be more accurate you'd need 5 * CLOCKS_PER_SECOND, but it's normally 1000 or thereabouts.
I think that will work. I don't have a compiler on here so don't sue me if I made a boo-boo.
// Woops, had to disables smilies again.
// Blah! I had to edit again because of the < > around time.h
hypermood
29 Sep 2003, 8:39pm
Try
getc();
This will block execution until you hit a key. This usually acts as an adequate pause like function.
a2jfreak
29 Sep 2003, 9:00pm
I think you mean getchar();
Then just press enter to quit.
hypermood
29 Sep 2003, 9:58pm
Yes I did, a2jfreak. getc need the input stream as an argument.
make sure you arent running the debugger...if the debugger is turned on it will close right away like you described. With it off it should stay up automatically
vBulletin® v3.8.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.