C语言中如果实现--在某个固定时间执行某段特定代码

我想实现这么一个功能!在我的进程里面,我想在每天的某个特定时间(比如4点),执行某个函数!这个怎么实现!是不是有某个函数可以执行,我暂时的实现方法是这样的!在我的while循环里面,每次都提前当前时间,然后和那个特定时间(只比较小时 分 秒)作个差!如果时间差在某个范围之内则表示条件满足!!但总觉得这样比较傻!有没有其他方法

你就读取系统时间就可以了啊。
void gettime(struct date *t),t 存放得到的日期信息
例子:
#include <stdio.h>
#include <dos.h>
int main(void)
{
struct time t;
gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d",t.ti_hour,t.ti_min, t.ti_sec, t.ti_hund);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答