title: define time intervals in C
body: <p>I want to define time intervals in C.<br>
  For example I want to execute some task every 20 seconds; is the below code correct for this task?</p>
  
  <p>for clarify, our goal in works with time intervals. for example i want to read packets every 20 second and in the end of each interval i want to change some parameters.</p>
  
  <pre><code>double blocktime = 20.000000;
  clock_t current, next;
  
  current = clock();
      while(trace_read_packet(trace,packet)&gt; 0 ){
          //doing some tasks
          next = clock(); 
          if ((double((next - current) / CLOCKS_PER_SEC))== blocktime) // if it is end of the  interval do some tasks
          {
                            //doing some task
              current = next;
  
          }
      }//end of while
  </code></pre>
  
  <p>and other questions how i can define loops that works with times?</p>