1
0
mirror of https://github.com/chylex/Advent-of-Code.git synced 2025-06-13 02:34:05 +02:00
Advent-of-Code/2015/01/main.c
2021-11-30 04:38:55 +01:00

34 lines
699 B
C

#include "stdio.h"
#define BUFFER_SIZE 256
int walkFloors(int currentFloor, char* instructions, size_t instructionCount);
int main() {
FILE* file;
errno_t openErr = fopen_s(&file, "input/1.txt", "rb");
if (openErr != 0 || !file) {
printf("Error opening input file, code %d\n", openErr);
return 1;
}
int floor = 0;
char buffer[BUFFER_SIZE];
while (!feof(file)) {
size_t readBytes = fread_s(&buffer, BUFFER_SIZE, 1, BUFFER_SIZE, file);
int readErr = ferror(file);
if (readErr) {
printf("Error reading input file, code %d\n", readErr);
return 1;
}
floor = walkFloors(floor, buffer, readBytes);
}
fclose(file);
printf("Final floor: %d", floor);
return 0;
}