1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <stdio.h>
#include <time.h>
#include <windows.h>
COORD coord = {0, 0};
void gotoxy (int x, int y)
{
coord.X = x; coord.Y = y; // X and Y coordinates
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
void showClock(int x_1, int x_2, int x_3,int y){
long i = 0; /* Loop counter */
clock_t now = 0; /* Holds initial clock time */
int interval = 1; /* Seconds interval for o/p */
int elapsed = 0;
int min=0,MIN=0,hrs=0,sec=0;
int d=0,f=0;
now = clock();
/* Get current clock time */
for(i = 0L ; ; i++){
elapsed = (clock()-now)/CLOCKS_PER_SEC;
if(elapsed>=interval){
interval += 1;
if(elapsed%60==0){
min=elapsed/60;
d=60*min;
if(min%60==0){
hrs=min/60;
f=60*hrs;
}
}
sec=elapsed-d;
MIN=min-f;
if(hrs<10){
gotoxy(x_1,y);printf("0%d",hrs);
}else{
gotoxy(x_1,y);printf(":%d",hrs);
}
if(min<10){
gotoxy(x_2,y);printf(":0%d",MIN);
}else{
gotoxy(x_2,y);printf(":%2d",MIN);
}
if(sec<10){
gotoxy(x_3,y);printf(":0%d",sec);
}else{
gotoxy(x_3,y);printf(":%2d",sec);
}
}
}
}
int main()
{
showClock(2,4,7,4);
return 0;
}
|