Wait command help

[b][red]This message was edited by V-X at 2004-10-25 4:7:6[/red][/b][hr]
I need a command that makes the program wait for one second.

Anyone?


Comments

  • : [b][red]This message was edited by V-X at 2004-10-25 4:7:6[/red][/b][hr]
    : I need a command that makes the program wait for one second.
    :
    : Anyone?
    :
    :
    :

    depends on the operating system: MS-DOS (none), MS-Windows, Sleep(int milliseconds), *nix, sleep(int seconds).

    Some MS-DOS compilers such as TurboC have delay().
  • Im doing it in DOS. Theres have to be a way, even in Pascal there was.

    Im using the libs:




    And I need it, to make a rand% work correctly.
  • : Im doing it in DOS. Theres have to be a way, even in Pascal there was.
    :
    : Im using the libs:
    :
    :
    :
    :
    : And I need it, to make a rand% work correctly.
    :

    what compiler are you using? What version of MS-DOS? If its just a console program using a 32-bit compiler then use the Windows Sleep() function.
  • : Im doing it in DOS. Theres have to be a way, even in Pascal there was.
    :
    : Im using the libs:
    :
    :
    :
    :
    : And I need it, to make a rand% work correctly.
    :

    These functions will work for fairly accurate delays:

    [code]

    void MicroDelay(long MicroSecs) // delay in microseconds (1,000,000 per second)
    {
    _asm {
    mov cx, word ptr [MicroSecs+2]
    mov dx, word ptr [MicroSecs]
    mov ah, 0x86
    int 0x15
    }
    }

    void MilliDelay(long MilliSecs) // delay in milliseconds (1000 per second)
    {
    MicroDelay (MilliSecs * 1000);
    }

    void SecondDelay( long seconds ) // delay in seconds
    {
    MicroDelay(seconds * 1000000);
    }

    [/code]
  • : Im doing it in DOS. Theres have to be a way, even in Pascal there was.
    :
    : Im using the libs:
    :
    :
    :
    :
    : And I need it, to make a rand% work correctly.
    :

    Here I cut out a small code snippet from my 8puzzle solver program from a while back. It uses srand (sequential rand) by using a seed value. Now I make sure that seed value is different from pulling off the number of seconds elapsed since 1970 via this code:

    time_t now = time(NULL); // Gives the no of secs elapsed between 01/01/1970 to the current time. (Value changes once a sec);
    int seed = now; // Random seed that will be different each time the program is run
    ...
    srand( seed ); // use srand to get a different random number sequence each time
    swapDir = (rand() % NO_SWAP_DIRS); // generate a random direction to scramble a swap

    basically this code generates a random direction in the UP, DOWN, LEFT, RIGHT direction. It is very efficient. Note use the now val and have a small while loop run until difference(now1, now2) >= 1 second.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories