#include <stdio.h>
#include<time.h>
struct clock
{
int hour;
int minute;
int second;
}CLOCK;
void Update(struct clock *p)
{ (*p).second++;
if ((*p).second == 60)
{ (*p).second = 0;
(*p).minute++;
}
if ((*p).minute == 60)
{(*p).minute = 0;
(*p).hour++;
}
if ((*p).hour == 24)
{ (*p).hour = 0;
}
}
void Display(struct clock *p)
{ printf("%2d:%2d:%2d\r", (*p).hour, (*p).minute,(*p).second);
}
void Delay()
{long t;
for (t=0; t<400000000; t++)
{ }
}
int main()
{
struct clock CLOCK;
struct clock *p;
p=&CLOCK;
long i;
time_t rawTime;
time( &rawTime );
struct tm *timeInfo = localtime( &rawTime );
(*p).hour = timeInfo->tm_hour; /*hour,minute,second赋初值*/
(*p).minute = timeInfo->tm_min;
(*p).second = timeInfo->tm_sec;
for (i=0; i<100000; i++) /*利用循环结构,控制时钟运行的时间*/
{
Update(p); /*时钟更新*/
Display(p); /*时间显示*/
Delay(); /*模拟延时1秒*/
}
}