title: Difference between clock_t and time_t or time(NULL) and clock()
body: <p>I just write a c program  to print integer value on every one second as a exercise,this program print the integer after wait for one second before printing the next integer so the program take 5 seconds to finish the execution.I am using <code>clock_t</code> and <code>time()</code> as timer and it works but when I use <code>clock_t</code> and <code>clock</code> as timer it doesn't work.</p>
  
  <p>As i know <code>time_t</code> and <code>time()</code> is the absolute time and using the seconds that elapsed since 1970.While <code>clock_t</code> and <code>clock()</code> use the time since program run. </p>
  
  <p>This is the first code using <code>time_t</code> and <code>time(NULL)</code></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  int main (void) {
    int i;
    int sec=1;
    time_t start,end;
  
    start=time(NULL);
  
    for(i=1;i&lt;=5;i++){
       time_t wait=sec+time(NULL);
       while(time(NULL) &lt; wait) {}
       printf("%d\n",i);
    }
    end=time(NULL);
    printf("program take %d second\n",(unsigned int)difftime(end,start));
    return 0;
  }
  </code></pre>
  
  <p>and this is the result when the program run:</p>
  
  <pre><code>1
  2
  3
  4
  5
  program take 5 second
  </code></pre>
  
  <p>execution of the program exactly print the integers on every one second or wait one second
  before printing the next integer</p>
  
  <p>this is the second program using <code>clock_t</code> and <code>clock()</code></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  int main (void) {
     int sec=1;
     int i;
     clock_t start,end;
  
     start=clock();
  
     for(i=1;i&lt;=5;i++){
         clock_t wait=sec*CLOCKS_PER_SEC;
         while(clock ()&lt;wait){}
         printf("%d\n",i);
     }
  
    end=clock();
    printf("the program take %lf second\n",(double)(end-start)/CLOCKS_PER_SEC);
    return 0;
  }
  </code></pre>
  
  <p>This is the result of second program using <code>clock_t</code> and <code>clock()</code></p>
  
  <pre><code>1
  2 
  3
  4
  5
  the program take 0.998901 second
  </code></pre>
  
  <p>and after the execution it doesn't print exactly every one second but first wait for one second and then print all of the integers instead of wait for one second before print the next integer.</p>
  
  <p>Please explain what happen to the second program and what exactly the difference between 
  time() and clock() function? </p>