-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarmclock.c
79 lines (60 loc) · 1.42 KB
/
alarmclock.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
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
struct Alarm
{
time_t setTime;
};
void setAlarm(struct Alarm alarms[], int *pos)
{
char date[10];
char timestamp[8];
char str[20];
printf("Schedule alarm at which date? ");
scanf("%s", date);
printf("and time? ");
scanf("%s", timestamp);
printf("Date: %s\n", date);
printf("Time: %s\n", timestamp);
strlcat(str, date, 10);
strlcat(str, " ", 1);
strlcat(str, timestamp, 8);
printf("%s", str);
struct tm t;
strptime(str, "%Y-%m-%s %H:%M:%S", &t);
alarms[*pos].setTime = mktime(&t);
*pos += 1;
// fork();
}
void listAlarms(struct Alarm *alarms) {
for (int i = 0; i < 10; i++)
{
printf("");
}
}
int main()
{
char choice;
time_t current_time;
current_time = time(NULL);
printf("Welcome to the alarm clock! It is currently %s", ctime(¤t_time));
printf("Please enter \"s\" (schedule), \"l\" (list), \"c\" (cancel), \"x\" (exit)\n");
scanf("%c", &choice);
struct Alarm alarms[10];
int countAlarms = 0;
if (!strcmp(&choice, "s"))
{
setAlarm(alarms, &countAlarms);
printf("Num alarms: %d\n", countAlarms);
}
else if (!strcmp(&choice, "l"))
{
listAlarms(alarms);
}
else if (!strcmp(&choice, "c") || !strcmp(&choice, "x"))
{
// code here
}
return 0;
}