From 67e6174ceefddfbdcafdb27f4b2c432cc2d4987a Mon Sep 17 00:00:00 2001 From: baeSM726 <53217246+baeSM726@users.noreply.github.com> Date: Thu, 15 Aug 2019 00:24:45 +0900 Subject: [PATCH] . --- "\354\206\214\354\212\244.cpp" | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "\354\206\214\354\212\244.cpp" diff --git "a/\354\206\214\354\212\244.cpp" "b/\354\206\214\354\212\244.cpp" new file mode 100644 index 0000000..1fbcbae --- /dev/null +++ "b/\354\206\214\354\212\244.cpp" @@ -0,0 +1,55 @@ +#include +#include // _getch() +#include // time() + +void stopwatch(int onOff); +void secToHHMMSS(int secs, char* s, size_t size); + +char timerBuffer[8 + 1]; // 06:17:20 µîÀÇ °æ°ú ½Ã°£ ¹®ÀÚ¿­ÀÌ ÀúÀåµÉ ¹öÆÛ Á¤ÀÇ + + +int main(void) { + + stopwatch(1); // 1À» Àμö·Î ³ÖÀ¸¸é ŸÀ̸Ӱ¡ ÄÑÁü + puts("ŸÀÌ¸Ó ON! ¾Æ¹«Å°³ª ´©¸£¸é Á¾·á"); + + + // À¯Àú°¡ ¾Æ¹« Å°³ª ´©¸¦ ¶§±îÁö ¹«ÇÑÁ¤ ´ë±â + _getch(); // _getch() ´Â getch() ÀÇ º¸¾È °­È­ ¹öÀü + + + stopwatch(0); // 0À» ³ÖÀ¸¸é ŸÀ̸Ӱ¡ ²¨Áö°í ½Ã°£ ¹®ÀÚ¿­À» ¹öÆÛ¿¡ ¼³Á¤ + printf("ŸÀÌ¸Ó OFF! °æ°ú ½Ã°£Àº: [%s]\n", timerBuffer); + + + return 0; +} + + +void stopwatch(int onOff) { + static int oldTime; // stopwatch ÇÔ¼ö°¡ Á¾·áµÇ¾îµµ °ªÀ» ±â¾ïÇÏ´Â "Á¤Àû Áö¿ª º¯¼ö" + + if (onOff == 1) { // ŸÀÌ¸Ó Äѱâ + oldTime = (int)time(NULL); + } + + if (onOff == 0) { // ŸÀÌ¸Ó ²ô°í, ½ÃºÐÃʸ¦ timerBuffer ¿¡ ÀúÀå + secToHHMMSS( + (int)time(NULL) - oldTime, + timerBuffer, + sizeof(timerBuffer) + ); + } + +} + + +void secToHHMMSS(int secs, char* s, size_t size) { // Á¤¼ö·Î µÈ ÃÊ(sec)¸¦ ÀÔ·Â ¹Þ¾Æ, "06:17:20" µîÀÇ Çü½ÄÀÇ ¹®ÀÚ¿­·Î ½ÃºÐÃʸ¦ ¹è¿­¿¡ ÀúÀå + int hour, min, sec; + + sec = secs % 60; + min = secs / 60 % 60; + hour = secs / 3600; + + sprintf_s(s, size, "%02d:%02d:%02d", hour, min, sec); +} \ No newline at end of file