Skip to content

Commit

Permalink
Correct windows-only error
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 16, 2024
1 parent 45f0c8d commit a498ff2
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion c/src/p0019.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <time.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

#ifdef _WIN32
#include <string.h>
#include <windows.h>
#else
#include <time.h>
#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;
Expand All @@ -46,6 +76,7 @@ uint16_t p0019() {
if (date.tm_wday == 0) {
++answer;
}
#endif
}
}
return answer;
Expand Down

0 comments on commit a498ff2

Please sign in to comment.