C语言模拟动态时钟程序

2025-01-06 13:02:50
推荐回答(2个)
回答1:

#include "stdio.h"
#include "dos.h"
//#include
#include

#define S2M_M2H 60

struct N
{
int hour;
int minute;
int second;
} mytime = {0,0,0};

int main()
{
time_t rt;
struct tm *t;
time ( &rt );
t = localtime ( &rt );
mytime.hour=t->tm_hour;
mytime.minute = t->tm_min;
mytime.second = t->tm_sec;
//1楼答得不错,你不会自己合直来么,我帮你合起来了
//以后我白天不能上网,晚上来答一两个就玩去了,这题如果可行,就采纳1楼的,我没功劳
for(; ; mytime.second++)
{
if(mytime.second==S2M_M2H)
{
mytime.minute++;
mytime.second=0;

if(mytime.minute==S2M_M2H)
{
mytime.hour++;
mytime.minute=0;
}
}
{
printf("\b\b\b\b\b\b\b\b%2d:%02d:%02d",mytime.hour,mytime.minute,mytime.second);
delay(1000);
}
}
return 0;
}

回答2:

加函数:
void delay ( int ms )
{
clock_t endwait;
endwait = clock () + ms / 1000.0 * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
---
时间初始化:
time_t rt;
struct tm *t;
time ( &rt );
t = localtime ( &rt );
mytime.hour=t->tm_hour;
mytime.minute = t->tm_min;
mytime.second = t->tm_sec;
其它不变。