지금 C 프로그래밍을 배우고 있는데, 나는 'Codeproject.com'의 카운트 다운 코드를 발견하고 그것을 실행하고 배우기로 결정했습니다. 그러나 카운트 다운 출력은 다음 번으로 이동하기 전에 수천 번 반복됩니다. 그 이유를 이해하는 데 도움이 필요합니다. 코드는 다음과 같습니다.카운터가 계속 대답을 제공하십시오.
#include <stdio.h>
#include <time.h>
int main()
{
unsigned int x_hours = 0;
unsigned int x_minutes = 0;
unsigned int x_seconds = 0;
unsigned int x_milliseconds = 0;
unsigned int totaltime = 0, count_down_time_in_secs = 0, time_left=0;
clock_t x_startTime, x_countTime;
count_down_time_in_secs = 10; // 1 min is 60
x_startTime = clock();
time_left = count_down_time_in_secs-x_seconds; //update timer
while (time_left>0)
{
x_countTime = clock();
x_milliseconds = x_countTime-x_startTime;
x_seconds=(x_milliseconds/(CLOCKS_PER_SEC))-(x_hours*60);
x_minutes=(x_milliseconds/(CLOCKS_PER_SEC))/60;
x_hours=x_minutes/60;
time_left = count_down_time_in_secs-x_seconds;
printf("\nyou have %d seconds left", time_left, count_down_time_in_secs);
}
printf("\n\n\nTime's out\n\n\n");
return 0;
}