From 83c618f861054ec5418c18394897c09d18499f48 Mon Sep 17 00:00:00 2001 From: jiriks74 Date: Tue, 3 Dec 2024 14:20:43 +0100 Subject: [PATCH] fix(01): Fix memory leaks, fix copyright, handle empty lines in input --- 01/src/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/01/src/main.c b/01/src/main.c index 165cafd..8a334c2 100644 --- a/01/src/main.c +++ b/01/src/main.c @@ -1,5 +1,5 @@ /** - * Copyright [2023] Jiří Štefka + * Copyright [2024] Jiří Štefka * Project: AdventOfCode * @file main.c * @brief Main entry point @@ -10,6 +10,7 @@ #include #include +#include #define INC_CHUNK = 64 @@ -72,14 +73,16 @@ int main(int argc, char *argv[]) rewind(file); for (uint i = 0; i < lines; i++) { - char *buffer = NULL; - size_t bufferSize = 0; if (getline(&buffer, &bufferSize, file) == -1) break; + if(strcmp(buffer, "")) continue; + sscanf(buffer, "%d %d", &array1[i], &array2[i]); } + free(buffer); + bufferSize = 0; fclose(file); qsort(array1, lines, sizeof(int), compareInt);