C
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
// C Military time by @HungryTradie
/*
Task:
Determine if the time you are given is AM or PM, then convert that value to the way that it would appear on a 24 hour clock.
*/
#include <stdio.h> //for standard input/output
#include <stdlib.h> //for malloc
#include <string.h> //for sscanf
int main() {
int hh,mm;
char am[3];
char *iw=NULL; //a pointer of char type
iw=malloc(10*sizeof(iw)); //allocating memory for the pointer to piont to.
//////////////////////// take input
fgets(iw,9,stdin);
sscanf(iw, "%d:%d %s", &hh, &mm, am);
// printf("%02d:%02d %s",hh,mm, am); // debugging
hh=hh%12; // modulo 12 to give 00: hours
if (am[0]=='P' || am[0]=='p') // simplistic check for PM.
hh+=12;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run