Pages

Sunday, August 28, 2011

How to show a Digital Clock on the Screen using C and C++ Program

Digital Clock
The following C and C++ program will show a digital clock on the output screen. The gettime() function is being used to catch current system time and then the time is being shown with the cprintf() function. The gettime() function accepts a structure type variable reference. So, the time structure variable is being used in this program. The delay() function is also being used to hold the program execution till 1 second or 1000ms.

C and C++ program to show an digital clock

#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main()
{

 struct time t;
 do
 {
  clrscr();
  gettime(&t);
  gotoxy(30,10);
  textcolor(2);
  cprintf("Time: %2d:%02d:%02d",t.ti_hour, t.ti_min, t.ti_sec);
  delay(1000);
 }while(!kbhit());

}

Output


4 comments:

shahanara said...

nice program. it is helpful.

Anonymous said...

Yes, very nice post. while looping statement is very powerful for continous. But now a days some other methods are used instead of looping. Will share on my blog soon. Have a visit to my blog.

Barik Riaz said...

What does !kbhit mean?

mukes said...

Sign up in ola app with referral code PMHV25 and earn Rs.100.
After signup use APP200 to get 200 more while riding or booking cab.Download the app from: www.ola.bz/b