From 6ee8e076d0b8630c4d78e7e88f1e44f5c7ba3854 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 9 Dec 2020 11:48:26 +0100 Subject: Git commit stack alloc when sensible --- 8/part1.c | 4 +--- 8/part2.c | 4 +--- 9/part1.c | 4 +--- 9/part2.c | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/8/part1.c b/8/part1.c index 6dbb058..d4261be 100644 --- a/8/part1.c +++ b/8/part1.c @@ -1,8 +1,6 @@ #include #include #include -#include -#include #define INPUT_LEN 650 @@ -20,7 +18,7 @@ int exe_program(const char *filename) // Include space for newline and string terminator char buffer[16] = { 0 }; - struct Operation *ops = malloc(INPUT_LEN * sizeof(struct Operation)); + struct Operation ops[INPUT_LEN]; size_t opcount = 0; while (fgets(buffer, 16, file)) { diff --git a/8/part2.c b/8/part2.c index ed539e1..44ebdec 100644 --- a/8/part2.c +++ b/8/part2.c @@ -1,8 +1,6 @@ #include #include #include -#include -#include #define INPUT_LEN 650 @@ -48,7 +46,7 @@ int exe_program(const char *filename) // Include space for newline and string terminator char buffer[16] = { 0 }; - struct Operation *ops = malloc(INPUT_LEN * sizeof(struct Operation)); + struct Operation ops[INPUT_LEN]; size_t opcount = 0; while (fgets(buffer, 16, file)) { diff --git a/9/part1.c b/9/part1.c index a89fa0c..d17fb2b 100644 --- a/9/part1.c +++ b/9/part1.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #define INPUT_LEN 1000 #define SEARCH_LEN 25 @@ -31,7 +29,7 @@ int exe_program(const char *filename) // Include space for newline and string terminator char buffer[24] = { 0 }; - uint64_t *nums = malloc(INPUT_LEN * sizeof(uint64_t)); + uint64_t nums[INPUT_LEN]; size_t num_size = 0; while (fgets(buffer, 24, file)) { diff --git a/9/part2.c b/9/part2.c index ceab610..e926a60 100644 --- a/9/part2.c +++ b/9/part2.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #define INPUT_LEN 1000 #define SEARCH_LEN 25 @@ -31,7 +29,7 @@ int exe_program(const char *filename) // Include space for newline and string terminator char buffer[24] = { 0 }; - uint64_t *nums = malloc(INPUT_LEN * sizeof(uint64_t)); + uint64_t nums[INPUT_LEN] = { 0 }; size_t num_size = 0; while (fgets(buffer, 24, file)) { -- cgit v1.2.3