#include <stdio.h>
typedef struct clock
{
int hour,minute,second;
}CLOCK;
//函数功能:时分秒时间的更新
void Update(CLOCK *t)
{
t->second++;
if (t->second == 60)
{
t->second=0;
t->minute++;
/* code */
}
if (t->minute ==60)
{
t->minute = 0;
t->hour++;
/* code */
}
if (t->hour == 24)
{
t->hour=0;
/* code */
}
}
//函数功能:时、分、秒时间的显示;
void Display(CLOCK *t)
{
printf("%2d:%2d:%2d\n",t->hour,t->minute,t->second);
}
//函数功能:模拟延迟1s的时间
void Delay(void)
{
long t;
for (t = 0; t<50000000 ; ++t)
{
/* code */
}
}
int main()
{
CLOCK myclock;
myclock.hour=myclock.minute=myclock.second=0;
for (long i = 0; i < 100000; ++i)
{
Update(&myclock);
Display(&myclock);
Delay();
/* code */
}
return 0;
}
结构体实现模拟时钟
最新推荐文章于 2021-05-24 16:13:23 发布