One thing I have been pondering over the past few days is how to calculate the total time of my PC from power-on to the present.
Finally, let's look at this function: gettickcount ();
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:
1 # include <stdlib. h> 2 # include <time. h> 3 # include <windows. h> 4 # include <stdio. h> 5 6 typedef struct node 7 {8 int h; 9 int m; 10 int s; 11} * ptime; 12 13 void sleep (long wait ); 14 15 void gettime (); 16 17 int main () 18 {19 ptime times; 20 int flag = 1; 21 char time [1, 128]; 22 do23 {24 _ strtime (time); // gets the current system time (do not include the date) 25 system ("CLS "); // clear screen26 printf ("OS time: % s \ n", time); 27 28 gettime (times); // call gettime () 29 sleep (1000 ); // sleep 1 second30 31 printf ("started Time: % 02d hour % 02d minute % 02d second \ n", times-> H, times-> m, times-> S); 32} while (FLAG); // always cycle33 34 return 0; 35} 36 37 void sleep (long wait) 38 {39 long goal; // define total time40 goal = wait + clock (); 41 while (Goal> clock (); 42} 43 44 ptime gettime (ptime T) 45 {46 int I = gettickcount (); 47 t-> H = (I/1000)/3600; 48 t-> M = (I/1000) /60-T-> H * 60; 49 T-> S = (I/1000)-T-> H * 3600-T-> M * 60; 50 return T; 51}