Thứ Sáu, 2 tháng 6, 2017

Tạo trình đếm thời gian.


Video:
 



Code trong video:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include "graphics.h"
#include <time.h>
#pragma comment(lib,"graphics.lib")

char* chuyenSoThanhChu(int n)
{
 char s[3] = { '\0' };
 if (n < 9)
 {
  s[0] = '0';
  itoa(n, s+1, 10);
 }
 else
 {
  itoa(n, s, 10);
 }
 return s;
}

int main()
{
 initwindow(400, 400, "Test Time", 100, 100);
 time_t timeBegin = time(NULL); // Thoi gian moc
 char s[3];
 rectangle(90, 90, 150, 125);
 while (!kbhit()) // Lap cho den khi nhan phim bat ki
 {
  int thoiGianChenhLech = (int)difftime(time(NULL), timeBegin);
  thoiGianChenhLech += 58; // test thu
  // Nho hon 60
  if (thoiGianChenhLech < 60)
  {
   // in ra luon :v
   outtextxy(100, 100, "00");
   outtextxy(120, 100, ":");
   strcpy(s, chuyenSoThanhChu(thoiGianChenhLech));
   outtextxy(127, 100, s);
  }
  else
  {
   strcpy(s, chuyenSoThanhChu(thoiGianChenhLech / 60));//  Phut
   outtextxy(100, 100, s);
   outtextxy(120, 100, ":");
   strcpy(s, chuyenSoThanhChu(thoiGianChenhLech % 60)); // Giay
   outtextxy(127, 100, s);
  }
 }
 closegraph();
 return 0;
}

Không có nhận xét nào:

Đăng nhận xét