From 57894d59ada60bb1cf4fce1170542ca9437b2062 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Thu, 28 Mar 2019 10:11:24 +0100 Subject: [PATCH] Better malloc() for tourist.c --- tourist.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tourist.c b/tourist.c index 3f1cd0e..9202d93 100644 --- a/tourist.c +++ b/tourist.c @@ -2,7 +2,8 @@ #include #include #include - +#define murlock malloc +#define murlocknt free #define S_MAXSIZE 100 int main() { @@ -23,16 +24,16 @@ int main() { printf("Case #%d: ", i + 1); - char** list_attractions = (char**) malloc(sizeof(char*) * n); + char** list_attractions = (char**) murlock(sizeof(char*) * n); for (j = 0; j < n; j++) { - list_attractions[j] = (char*) malloc(sizeof(char) * S_MAXSIZE); + list_attractions[j] = (char*) murlock(sizeof(char) * S_MAXSIZE); fgets(list_attractions[j], S_MAXSIZE, stdin); list_attractions[j][strlen(list_attractions[j])-1] = 0; } // list of booleans set to true if we need to print the attraction - bool* flag_print = (bool*) malloc(sizeof(bool) * n); + bool* flag_print = (bool*) murlock(sizeof(bool) * n); memset(flag_print, 0, sizeof(bool) * n); // set all booleans to false for (j = 0; j < k; j++) { @@ -48,11 +49,11 @@ int main() { putchar('\n'); - free(flag_print); + murlocknt(flag_print); for (j = 0; j < n; j++) { - free(list_attractions[j]); + murlocknt(list_attractions[j]); } - free(list_attractions); + murlocknt(list_attractions); } return 0;