c语言编写计时器实现开始,暂停并显示时长,清零

void update (Clock&clock, int mode)
clock. millisecond++;
if (clock. millisecond==60)

clock.millisecond=O:
clock. second++;

说要在第二行代码上做文章

你可以使用c语言demo中的例子

/* clock example: frequency of primes */
#include <stdio.h>      /* printf */
#include <time.h>       /* clock_t, clock, CLOCKS_PER_SEC */
#include <math.h>       /* sqrt */

int frequency_of_primes (int n) {
  int i,j;
  int freq=n-1;
  for (i=2; i<=n; ++i) for (j=sqrt(i);j>1;--j) if (i%j==0) {--freq; break;}
  return freq;
}

int main ()
{
  clock_t t;
  int f;
  t = clock();
  printf ("Calculating...\n");
  f = frequency_of_primes (99999);
  printf ("The number of primes lower than 100,000 is: %d\n",f);
  t = clock() - t;
  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}

img


它执行的时候,把函数放在中间。
计算了什么时候开始 什么时候停止。
你可以使用它。
一些文档:
http://www.cplusplus.com/reference/ctime/clock/