To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
RWB
Thank God for Blue Monsters
RWB
7,356 Posts

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
madasiemanym
a2jfreak
3,351 Posts
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.
__________________
One thing kids like is to be tricked. For instance, I was going to take my little nephew to Disneyland, but instead I drove him to an old burned-out warehouse. "Oh, no," I said. "Disneyland burned down." He cried and cried, but I think that deep down, he thought it was a pretty good joke. I started to drive over to the real Disneyland, but it was getting pretty late.
Jack Handey
[folding_sig1]Child Search Ministries.
A Christian Charity for Missing Children.

Get Firefox!
RWB
Thank God for Blue Monsters
RWB
7,356 Posts
Dirty is no good.
a2jfreak
madasiemanym
a2jfreak
3,351 Posts
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
Go Jackets!
hypermood
166 Posts
Try

getc();

This will block execution until you hit a key. This usually acts as an adequate pause like function.
__________________ DFI NF4 SLI-DR Expert (BIOS 04/06/2006)
AMD Athlon 64 X2 4800+ Toledo (250x10)
PDC2G3500LLK 2GB Dual Channel (DDR500 2.68V)
Palit 8800GT SONIC 1GB PCI-E x16 (650/1900)
Seagate 160GB x 2 SATA
Plextor PX-716 DVD+/-RW DL IDE
Pioneer DVR-112D DVD+/-RW DL IDE Labelflash
OCZ ModStream 520W

[folding_sig1]
a2jfreak
madasiemanym
a2jfreak
3,351 Posts
I think you mean getchar();
Then just press enter to quit.
hypermood
Go Jackets!
hypermood
166 Posts
Yes I did, a2jfreak. getc need the input stream as an argument.
JB
Radeon_Man in another life
JB
417 Posts
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
Go Back   Icrontic Forums > Tech: Software > Web & Digital Media
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 1:57pm (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.