-
Notifications
You must be signed in to change notification settings - Fork 0
/
12HR_TO_24HR.c
62 lines (61 loc) · 935 Bytes
/
12HR_TO_24HR.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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char time[11]; // TIME FORMAT 12:12:12AM HH:MM:SSAM/PM
fgets(time, 11, stdin);
if (time[8] == 'A')
{
char hh[2];
for (int i = 0; i < 2; i++)
{
hh[i] = time[i];
}
int hour = atoi(hh);
if (hour == 12)
{
for (int i = 0; i < 2; i++)
{
time[i] = '0';
}
time[8] = '\0';
fputs(time, stdout);
}
else
{
time[8] = '\0';
fputs(time, stdout);
}
}
else if (time[8] == 'P')
{
char hh[2];
for (int i = 0; i < 2; i++)
{
hh[i] = time[i];
}
int hour = atoi(hh);
if (hour == 12)
{
time[8] = '\0';
fputs(time, stdout);
}
else
{
hour += 12;
sprintf(hh, "%d", hour);
for (int i = 0; i < 2; i++)
{
time[i] = hh[i];
}
time[8] = '\0';
fputs(time, stdout);
}
}
else
{
printf("Invalid input.");
}
return 0;
}