-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimple.c
43 lines (34 loc) · 1.15 KB
/
Simple.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
#include <stdio.h>
#include <time.h>
#include <unistd.h> // For sleep function
int main() {
int alarmHour, alarmMinute;
time_t currentTime;
struct tm *localTime;
// Get the current time
time(¤tTime);
localTime = localtime(¤tTime);
// Input alarm time
printf("Enter alarm time (24-hour format)\n");
printf("Hour: ");
scanf("%d", &alarmHour);
printf("Minute: ");
scanf("%d", &alarmMinute);
// Ensure the alarm time is valid
if (alarmHour < 0 || alarmHour > 23 || alarmMinute < 0 || alarmMinute > 59) {
printf("Invalid time entered.\n");
return 1;
}
printf("Alarm set for %02d:%02d\n", alarmHour, alarmMinute);
// Loop until the current time matches the alarm time
while (1) {
time(¤tTime);
localTime = localtime(¤tTime);
if (localTime->tm_hour == alarmHour && localTime->tm_min == alarmMinute) {
printf("ALARM! The time is now %02d:%02d\n", localTime->tm_hour, localTime->tm_min);
break;
}
sleep(30); // Check every 30 seconds
}
return 0;
}