forked from MAYANK25402/Hactober-2023-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.c
85 lines (73 loc) · 2.12 KB
/
clock.c
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
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
void clrscr()
{
system("@cls||clear");
}
char pdigits[11][26] = {
" ### # ## ## # ### ",
" # ## # # # ",
"##### ####### #####",
"##### # ### ######",
"# # # ##### # # ",
"###### ##### ######",
"###### ###### ######",
"##### # # # # ",
"###### ####### ######",
"###### ###### ######",
" # # "
};
void format_time(char *output){
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
sprintf(output, "[%d %d %d %d:%d:%d]", timeinfo->tm_mday,
timeinfo->tm_mon + 1, timeinfo->tm_year + 1900,
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
}
typedef struct Digits {
char h1;
char h2;
char m1;
char m2;
char s1;
char s2;
} Digits;
Digits convert_time(struct tm *timeinfo) {
Digits digits;
digits.h1 = timeinfo->tm_hour / 10;
digits.h2 = timeinfo->tm_hour % 10;
digits.m1 = timeinfo->tm_min / 10;
digits.m2 = timeinfo->tm_min % 10;
digits.s1 = timeinfo->tm_sec / 10;
digits.s2 = timeinfo->tm_sec % 10;
return digits;
}
int main(void)
{
while (1) {
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
clrscr();
Digits digits = convert_time(timeinfo);
for (int i = 0; i < 5; i++) {
printf("%.5s ", pdigits[digits.h1] + 5 * i);
printf("%.5s", pdigits[digits.h2] + 5 * i);
printf("%.5s", pdigits[10] + 5 * i);
printf("%.5s ", pdigits[digits.m1] + 5 * i);
printf("%.5s", pdigits[digits.m2] + 5 * i);
printf("%.5s", pdigits[10] + 5 * i);
printf("%.5s ", pdigits[digits.s1] + 5 * i);
printf("%.5s\n", pdigits[digits.s2] + 5 * i);
}
// printf("%d %d %d %d %d %d\n", digits.h1, digits.h2, digits.m1, digits.m2, digits.s1, digits.s2);
sleep(1);
}
return 0;
}