1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-07-18 02:20:12 +02:00

fix(solutions): char* issues with memory allocation

This commit is contained in:
Théo LUDWIG 2023-07-02 17:37:35 +02:00
parent 9c5c2ee48b
commit e2300b117f
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B

View File

@ -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);