计时器程序以调用c中的函数 [英] timer program to call function in c

查看:102
本文介绍了计时器程序以调用c中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想实现一个计时器,程序每5秒就会在其中调用一个函数.

我尝试在此代码中实现,但是它在for循环的内部很容易实现

Hi ,

I want to implement a timer in which program calls a function after every 5 seconds .

I tried to implement in this code but it is strucking in the inner for loop

#include<stdio.h>
#include<time.h>

int main()
{
 int a =10;
 int i=0;

 time_t seconds;
 seconds = time (NULL);
 for(;;)
 {
   for(;;)
   {
     if(time(NULL) - seconds <3)
     {
       printf("in if \n");
       foo();
       a++;
     }
     else
     {
       break;
     }
   }
   printf("%d",a);
  }
 return 0;
}

推荐答案

查看以下内容:
简单的C ++计时器包装器 [ http://cboard.cprogramming.com/c-programming/112560-timers-c.html [^ ]
Look at these:
Simple C++ Timer Wrapper[^]

http://cboard.cprogramming.com/c-programming/112560-timers-c.html[^]


这篇关于计时器程序以调用c中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆