+ 1
Doubt in Military Time.. In C
In Military time[code coach],If we input "12:00 P.M" as a input, then what is the output for that input...? Is that output be 12:00 or 24:00? In my below code,I considered that 12:00 P.M == 24:00. Is it correct? Please clear my doubt... https://code.sololearn.com/cmyVfgitl9fA/?ref=app
8 Answers
+ 1
In military time,
12PM is 12:00
the highest time availible is: 23:59
12AM is: 00:00
+ 2
Thank you Slick š š
+ 1
I don't understand "highest time available is 23:59" can you explain me it detaily......
+ 1
I mean it can go no higher than that.
11:59PM is 23:59
+ 1
Yogeshwaran looks scary! you could do this without any loops
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void printMT(const char* time)
{
char tmp[3];
const char* ptrT = time, *p = NULL;
p = strchr(time, ':');
strncpy(tmp, ptrT, (p - ptrT) == 1 ? 1 : 2);
int h = atoi(tmp);
strncpy(tmp, ++p, 2);
tmp[2] = '\0';
int m = atoi(tmp);
if ((ptrT = strstr(ptrT, "PM")) != NULL)
{
if (h != 12)
{
h += 12;
}
}
else
{
if (h == 12)
{
h = 0;
}
}
printf("%02d:%02d\n", h, m);
}
int main()
{
char time[9];
printMT(fgets(time, 9, stdin));
return 0;
}
https://code.sololearn.com/clmn4YgPm1d0/?ref=app
+ 1
Flash š
, this is my first try.....
So,only,I didn't care about that code's length......
and I only focus on outputš.....
and I also take one full day to complete this code......š
anyway thanks for yours comment on my codeš
+ 1
Yogeshwaran okay, btw, it was my first try as well :)
+ 1
Flash super š²ššššš