From a498ff24370c6a0845f26e38bfe00357e45a46f9 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Fri, 16 Aug 2024 17:59:47 -0500 Subject: [PATCH] Correct windows-only error --- c/src/p0019.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/c/src/p0019.c b/c/src/p0019.c index f4139d21..8b5a3ff4 100644 --- a/c/src/p0019.c +++ b/c/src/p0019.c @@ -23,17 +23,47 @@ How many Sundays fell on the first of the month during the twentieth century */ #ifndef EULER_P0019 #define EULER_P0019 -#include #include #include #include +#ifdef _WIN32 +#include +#include +#else +#include +#endif + uint16_t p0019() { uint16_t answer = 0; + +#ifdef _WIN32 + SYSTEMTIME systemTime; + FILETIME fileTime; + SYSTEMTIME normalizedTime; +#else struct tm date = {0}; +#endif for (int year = 1901; year <= 2000; ++year) { for (int month = 0; month < 12; ++month) { +#ifdef _WIN32 + memset(&systemTime, 0, sizeof(systemTime)); + systemTime.wYear = year; + systemTime.wMonth = month + 1; + systemTime.wDay = 1; + + if (!SystemTimeToFileTime(&systemTime, &fileTime)) { + return -1; + } + if (!FileTimeToSystemTime(&fileTime, &normalizedTime)) { + return -1; + } + + if (normalizedTime.wDayOfWeek == 0) { + ++answer; + } +#else date.tm_year = year - 1900; date.tm_mon = month; date.tm_mday = 1; @@ -46,6 +76,7 @@ uint16_t p0019() { if (date.tm_wday == 0) { ++answer; } +#endif } } return answer;