Skip to content

Instantly share code, notes, and snippets.

@z-------------
Last active November 7, 2019 10:53
Show Gist options
  • Save z-------------/e48dd1447c2272bbc32bc53936740f52 to your computer and use it in GitHub Desktop.
Save z-------------/e48dd1447c2272bbc32bc53936740f52 to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
const char month_name[12][10] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
size_t BUFSIZE = 10;
char* iso2eng(char* iso_str) {
char* result;
int num[3];
sscanf(iso_str, "%d-%d-%d", &num[0], &num[1], &num[2]);
asprintf(&result, "%s %d %d", month_name[num[1] - 1], num[2], num[0]);
return result;
}
int main(int argc, char** argv) {
char* buf;
if (argc > 1) {
buf = argv[1];
} else {
buf = (char*) malloc(BUFSIZE * sizeof(char));
getline(&buf, &BUFSIZE, stdin);
}
puts(iso2eng(buf));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment