fix(01): Fix memory leaks, fix copyright, handle empty lines in input
This commit is contained in:
parent
ab4e7a7edb
commit
83c618f861
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright [2023] Jiří Štefka <jiriks74>
|
* Copyright [2024] Jiří Štefka <jiriks74>
|
||||||
* Project: AdventOfCode
|
* Project: AdventOfCode
|
||||||
* @file main.c
|
* @file main.c
|
||||||
* @brief Main entry point
|
* @brief Main entry point
|
||||||
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define INC_CHUNK = 64
|
#define INC_CHUNK = 64
|
||||||
|
|
||||||
@ -72,14 +73,16 @@ int main(int argc, char *argv[])
|
|||||||
rewind(file);
|
rewind(file);
|
||||||
|
|
||||||
for (uint i = 0; i < lines; i++) {
|
for (uint i = 0; i < lines; i++) {
|
||||||
char *buffer = NULL;
|
|
||||||
size_t bufferSize = 0;
|
|
||||||
if (getline(&buffer, &bufferSize, file) == -1)
|
if (getline(&buffer, &bufferSize, file) == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if(strcmp(buffer, "")) continue;
|
||||||
|
|
||||||
sscanf(buffer, "%d %d", &array1[i], &array2[i]);
|
sscanf(buffer, "%d %d", &array1[i], &array2[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
bufferSize = 0;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
qsort(array1, lines, sizeof(int), compareInt);
|
qsort(array1, lines, sizeof(int), compareInt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user