Pages

Showing a Clock on the screen using C Language

Problem: How to show continuous time on the screen   

Solution

To show continuous time on the screen we can use gettime() function. gettime() function accepts a structure variable reference. Here we use structure type time to provide this reference.   The programming code for showing continuous time is given below

 

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

{

 struct time t;
 do
 {
  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

Remark
This is a program to show continuous time until a key is pressed. If we want to show a clock on the screen then we can use this program.

3 comments:

shahanara said...

nice program. it is helpful.

Sarang Mangi (SindhiTech) 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?