#include #include #include "age.h" void printf_color(const char* str, const char* col) { printf("%s%s%s", col, str, AC_RESET); } int main(int argc, char* argv[]) { struct tm birth, event; printf_color(" Date format: ", AC_GREEN); // intro printf_color("year-month-day\n", AC_YELLOW); printf_color(" Birth date: ", AC_GREEN); // birth printf(AC_YELLOW); scanf("%d-%d-%d", &birth.tm_year, &birth.tm_mon, &birth.tm_mday); printf_color(" Event date: ", AC_GREEN); // event printf(AC_YELLOW); scanf("%d-%d-%d", &event.tm_year, &event.tm_mon, &event.tm_mday); birth.tm_mday--; event.tm_mday--; // compute birth.tm_mon--; event.tm_mon--; int age = event.tm_year - birth.tm_year; if ((birth.tm_mon > event.tm_mon) || ((birth.tm_mon == event.tm_mon) && (birth.tm_mday > event.tm_mday))) { age--; } printf("%s Age: %s%d%s\n", AC_GREEN, AC_BLACK_ON_WHITE, age, AC_RESET); return 0; }