Computer boot time calculation code _c language

Source: Internet
Author: User
Tags clear screen sleep

function function: GetTickCount returns (retrieve) the number of milliseconds from the operating system boot to the current (elapsed), and its return value is DWORD.

Knowing this, this program is not a difficult thing ...

CODE:

Copy Code code 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];
Todo
{
_strtime (time); Gets the current system time (does not include the date)
System ("CLS"); Clear Screen
printf ("OS Time:%s\n", time);

GetTime (times); Call GetTime ()
Sleep (1000); Sleep 1 Second

printf ("Power-on time:%02d hours%02d minutes%02d seconds \ 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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.