要点:
1.进制转换(类比十进制)
2.time(NULL)获取到的是从1970.1.1.0:0:0至now的时间差(以秒的形式)
3.当键盘敲击任意键时,停止程序,避免死循环. 利用kbhit()函数,要#include<conio.h>
4.system()调用命令解释器, 利用system(“cls”)实现清屏, 要#include<stdlib.h>
5.Sleep()函数以毫秒为单位,Sleep(1000)延迟一秒钟, 要
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <windows.h>
typedef struct time
{
int hour;
int minute;
int second;
}TIME;
void fun(TIME *now);
int main(){
TIME now;
int seconds;
seconds=time(NULL);
now.hour=seconds/3600%24+8;
now.minute=seconds/60%60;
now.second=seconds%60;
while(!kbhit()){
fun(&now);
printf("%d:%d:%d\n",now.hour,now.minute,now.second);
Sleep(1000);
system("cls");
}
}
void fun(TIME *now){
now->second++;
if(now->second>=60){
now->second=0;
now->minute++;
if(now->minute>=60){
now->minute=0;
now->hour++;
now->hour%=24;
}
}
}