How to make a time based regular function?Like something that plays a sound every 1 second?

How to make a time based regular function?Like something that plays a sound every 1 second?

well, with the information that you provide this could work:

#include <iostream>

using namespace std;

void doSomething();

int main()
{
    int waittime = 5; // 5 seconds

    while(1)
    {
        doSomething();

        sleep(waittime);
    }
}

void doSomething()
{
    cout << "something done!" << endl;
}

Thanks.Can you link me to a page with more detailed info?

>How to make a time based regular function?
>Like something that plays a sound every 1 second?

To what end? If all you want to do is hog the process and play a sound every second, it's a trivial matter:

#include <iostream>
#include <windows.h>

void kindadumb()
{
  for ( ; ; ) {
    std::cout<<'\a';
    Sleep ( 1000 );
  }
}

int main()
{
  kindadumb();
}

But if you want something to happen while that function is running, you get into troublesome code such as faking multithreading, using actual threads, or spawning a separate process. How you're going to use the function plays a big part in how it needs to be implemented.

From your other posts, I'm guessing Win32.
So how about a WM_TIMER message?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.