-
Notifications
You must be signed in to change notification settings - Fork 2
/
clock.c
37 lines (33 loc) · 820 Bytes
/
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
#include "headers.h"
void clock_display(char *token)
{
char st[100][100];
int k = 0;
while (token != NULL)
{
strcpy(st[k++], token);
token = strtok(NULL, " \n\t\r");
}
int rem = atoi(st[2]);
int n = (atoi(st[4]) / rem) + 1;
char d[40], t[40];
strcpy(d, "/sys/class/rtc/rtc0/date");
strcpy(t, "/sys/class/rtc/rtc0/time");
while (n--)
{
FILE *fp = fopen(d, "r");
char dinfo[100], tinfo[100];
fgets(dinfo, sizeof d, fp);
int l = strlen(dinfo);
dinfo[l - 1] = '\0';
printf("%s, ", dinfo);
fclose(fp);
fp = fopen(t, "r");
fgets(tinfo, sizeof t, fp);
l = strlen(tinfo);
tinfo[l - 1] = '\0';
printf(" %s\n", tinfo);
fclose(fp);
sleep(rem);
}
}