#include <stdio.h>
//结构体,并起别名
typedef struct student
{
int second;
int minute;
int hour;
};
void Update(struct student *p);
void Display(struct student *p);
void Delay();
//主函数
int main()
{
//long i;
struct student a,*p;
a.second=-1;
a.minute=0;
a.hour=0;
p=&a;
Update(p);
return 0;
}
//时间更新,并判断是否在正常值以内
void Update(struct student *p)
{
struct student a;
while (p->second<61)
{if (p->second>=59)
{
p->second=p->second-60;
p->minute=p->minute+1;
}
if (p->minute>=59)
{
p->minute=p->minute-60;
p->hour=p->hour+1;
}
if (p->hour>=23)
p->hour=p->hour-24;
p->second=p->second+1;
Display(p);
Delay();
}
}
//输出时间
void Display(struct student *p)
{
printf ("%2d:%2d:%2d\r",p->hour,p->minute,p->second);
}
//时间更新一秒,进行300000000次空语句循环
void Delay()
{
long h=0;
while (h!=300000000)
{h++;
}
}
转载于:https://my.oschina.net/GodStaff/blog/210528