Function: GetTickCount returns the number of milliseconds that have elapsed since the operating system was started (elapsed). The returned value is DWORD.
Knowing this, this program is not difficult...
CODE:
Copy codeThe Code is as follows: # include <stdlib. h>
# Include <time. h>
# Include <windows. h>
# Include <stdio. h>
Typedef struct node
{
Int h;
Int m;
Int s;
}
* PTime;
Void sleep (long wait );
Void gettime ();
Int main ()
{
PTime times;
Int flag = 1;
Char time [128];
Do
{
_ Strtime (time); // Gets the current system time (do not include the date)
System ("cls"); // clear screen
Printf ("OS time: % s \ n", time );
Gettime (times); // call gettime ()
Sleep (1000); // sleep 1 second
Printf ("boot time: % 02d hour % 02d minute % 02d second \ n", times-> h, times-> m, times-> s );
} While (flag); // always cycle
Return 0;
}
Void sleep (long wait)
{
Long goal; // define total time
Goal = wait + clock ();
While (goal> clock ());
}
PTime gettime (PTime T)
{
Int I = GetTickCount ();
T-> h = (I/1000)/3600;
T-> m = (I/1000)/60-T-> h * 60;
T-> s = (I/1000)-T-> h * 3600-T-> m * 60;
Return T;
}