Source.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <Windows.h>
  5. BOOL work = TRUE;
  6. void* secondsmer() {
  7. int start, end;
  8. int ms = 0;
  9. int ns = 0;
  10. int sec = 0, min = 0, hrs = 0;
  11. start = clock();
  12. while (work)
  13. {
  14. end = clock();
  15. ns = end - start;
  16. ms = ns / 10;
  17. if (ms > 100)
  18. {
  19. sec = sec + 1;
  20. ms = ms - 100;
  21. start = end;
  22. }
  23. if (sec > 59)
  24. {
  25. min = min + 1;
  26. sec = 0;
  27. }
  28. if (min > 59)
  29. {
  30. hrs = hrs + 1;
  31. min = 0;
  32. }
  33. printf("%d:%d:%d.%d\n", hrs, min, sec, ms);
  34. }
  35. }
  36. int main()
  37. {
  38. system("chcp 1251 >null");
  39. DWORD choose = -1;
  40. HANDLE hTread = NULL;
  41. printf("\n1 - ñåêóíäîìåð\n0 - Îñòàíîâèòü\n");
  42. while (1)
  43. {
  44. scanf_s("%d", &choose);
  45. if (choose == 1) {
  46. if (hTread == NULL) {
  47. hTread = CreateThread(NULL, 0, secondsmer, 0, NULL, NULL);
  48. work = TRUE;
  49. }
  50. }
  51. else
  52. {
  53. if (hTread != 0) {
  54. work = FALSE;
  55. CloseHandle(hTread);
  56. hTread = NULL;
  57. }
  58. }
  59. }
  60. }