#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>

void display_time(int hour, int min, long sec){
	system("cls");
	
	printf("디지털 stopwatch\n\n");
	printf("%02d:%02d:%02d\n\n", hour, min, sec);
	
	printf("Enter: 시작/정지\n");
	printf("R: 재시작\n");
	printf("Esc: 종료\n");
}

void time_pass(time_t start){
	time_t now;
	double total;
	int hour, min, sec;
	
	while(!_kbhit()){
		now = time(NULL);
		total = difftime(now, start);
		
		hour = int(total / 3600);
		min = int(int(total) % 3600) / 60;
		sec = int(total) % 60;
		
		display_time(hour, min, sec);
		Sleep(200);
	}
}

int main(void){
	int key; 
	time_t start;
	display_time(0,0,0);
	int run;
	
	while(1){
		key = _getch();
		
		if(key == 10 || key == 13){
			if(run == 0){
				start = time(NULL);
				time_pass(start);
				run = 1;
			}else if(run == 1){
				run = 0;
			}
			
			
		}else if(key == 'r' || key == 'R'){
			display_time(0,0,0);
			start = time(NULL);
			time_pass(start);
			
		}else if(key == 27){
			break;
		}
	}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: