C language/C++ alarm clock and timer can be realized (self-made C language music) with code

The following code is to ring a small alarm clock every ten minutes. It is very practical to control the time for study or work.

#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <stdlib.h>
time_t now;
int main()
{
    
    
    while(time(&now)%600 != 0)//至第一个十分钟,(time函数是将这个系统提供的时间结构体赋值为1970年1月1日至现在的秒数)
        sleep(1);//程序停止运行1秒
    while(1)
    {
    
    
        Beep(523,500);//音乐函数,参数是(音调,声音持续多少毫秒)
        Beep(587,500);
        Beep(659,500);
        Beep(698,500);
        Beep(784,500);
        Beep(880,500);
        Beep(980,500);
        Beep(1060,500);
        sleep(60*10-4);//十分钟闹钟一次,-4是因为上面这段音乐需要4s
    }
    return 0;
}

If you are lucky enough to help you, don't forget to give me a thumbs up~

Guess you like

Origin blog.csdn.net/weixin_47964723/article/details/123699602