Time Delays?

[b][red]This message was edited by Strobe at 2002-7-30 15:47:34[/red][/b][hr]
How does one implement a simple 3 second time delay? I've looked in alot of places on the web and one that seemed the easiest to use would be the supposed sleep() function of time.h But according to the compiler I'm using (Visual C++ 6.0) this function does not exist. Any help you could offer?

Comments

  • : How does one implement a simple 3 second time delay? I've looked in
    : alot of places on the web and one that seemed the easiest to use would
    : be the supposed sleep() function of time.h But according to the
    : compiler I'm using (Visual C++ 6.0) this function does not exist. Any
    : help you could offer?

    The 'sleep' function is not part of the ANSI/ISO standard (it is part of POSIX, though), so don't be surprised that it's not there. Since you say you're using MSVC, which can only produce Win32 executables, you should be able to use Sleep which will sleep for at least some amount of milliseconds (if you pass '0' it is an undocumented feature that it yeilds the thread's/process's time slice).
  • The time delay can depend on the operating system you
    are using. If this program is for Linux/UNIX you can
    use the sleep() function.
    Under Windows 32-bit programming, it is called Sleep()
    (note the upper case "S").

    Another way that should work on any system, is to
    get the current time using the time() function.
    Then translate the time to struct with localtime().
    You can then get the current number of seconds.
    Do this contiually until the seconds value of the time
    struct has changed three times.
    Crude, but it works.


    : [b][red]This message was edited by Strobe at 2002-7-30 15:47:34[/red][/b][hr]
    : How does one implement a simple 3 second time delay? I've looked in alot of places on the web and one that seemed the easiest to use would be the supposed sleep() function of time.h But according to the compiler I'm using (Visual C++ 6.0) this function does not exist. Any help you could offer?
    :
    :

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