C Puase Question

RWBRWB Icrontian
edited October 2003 in Internet & Media
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?

Comments

  • a2jfreaka2jfreak Houston, TX Member
    edited September 2003
    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.
  • RWBRWB Icrontian
    edited September 2003
    Dirty is no good.
  • a2jfreaka2jfreak Houston, TX Member
    edited September 2003
    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
  • hypermoodhypermood Smyrna, GA New
    edited September 2003
    Try

    getc();

    This will block execution until you hit a key. This usually acts as an adequate pause like function.
  • a2jfreaka2jfreak Houston, TX Member
    edited September 2003
    I think you mean getchar();
    Then just press enter to quit.
  • hypermoodhypermood Smyrna, GA New
    edited September 2003
    Yes I did, a2jfreak. getc need the input stream as an argument.
  • JBJB Carlsbad, CA
    edited October 2003
    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
Sign In or Register to comment.