简易计时器

#include <stdio.h>

#include <windows.h>

typedef struct {

  int hour, minute, second;

} TIME;

void rationalize(TIME* t) {

  int sc = 0;

  t->second += sc;

  sc = t->second / 60;

  t->second %= 60;

  t->minute += sc;

  sc = t->minute / 60;

  t->minute %= 60;

  t->hour += sc;

  t->hour %= 24;

}

void input(TIME* t) {

  scanf("%d%d%d", &t->hour, &t->minute, &t->second);

  rationalize(t);

}

void print(TIME* t) {

  printf("%02d:%02d:%02d\n", t->hour, t->minute, t->second);

}

void setTime(TIME* t, int hour, int min, int sec) {

  t->hour = hour;

  t->minute = min;

  t->second = sec;

}

void inc(TIME* t) {

  t->second++;

  if (t->second == 60) rationalize(t);

  Sleep(1000);

}

int main(int argc, char const* argv[]) {

  TIME t;

  setTime(&t, 10, 0, 0);

  rationalize(&t);

  int i;

  for (i = 0; i < 6000; i++) inc(&t), print(&t);

  return 0;

}

posted @ 2017-08-16 21:22  我大概是只废喵  阅读(121)  评论(0编辑  收藏  举报