From e2300b117f9426e1506741c158a150ddd4f390b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Sun, 2 Jul 2023 17:37:35 +0200 Subject: [PATCH] fix(solutions): char* issues with memory allocation --- .../solutions/c/function/solution.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenges/look-and-say-sequence-conway/solutions/c/function/solution.c b/challenges/look-and-say-sequence-conway/solutions/c/function/solution.c index 6740664..80c6402 100644 --- a/challenges/look-and-say-sequence-conway/solutions/c/function/solution.c +++ b/challenges/look-and-say-sequence-conway/solutions/c/function/solution.c @@ -8,7 +8,7 @@ int main() { char* string = input(); size_t string_length = strlen(string); - char* result = malloc(sizeof(char*) * (string_length + 1)); + char* result = malloc(sizeof(char) * (string_length + 1)); for (size_t index = 0; index < string_length; index++) { unsigned char number_of_appearances = 0; char value_to_search = string[index]; @@ -17,7 +17,7 @@ int main() { number_of_appearances++; iteration++; } - char* number_of_appearances_string = malloc(sizeof(char*) * (string_length + 1)); + char* number_of_appearances_string = malloc(sizeof(char) * (string_length + 1)); snprintf(number_of_appearances_string, sizeof(result), "%hhu", number_of_appearances); character_append_many(result, number_of_appearances_string); character_append(result, value_to_search);