From 5f4727386f6e00e5912d068afd614a55cc899d61 Mon Sep 17 00:00:00 2001 From: lahcenlachgar Date: Sun, 26 Jan 2020 07:06:43 -0800 Subject: [PATCH] make strdup handle string alocation --- exercism/hello_world/hello_world.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/exercism/hello_world/hello_world.c b/exercism/hello_world/hello_world.c index 45349900..74aaa5cb 100644 --- a/exercism/hello_world/hello_world.c +++ b/exercism/hello_world/hello_world.c @@ -4,10 +4,7 @@ const char *hello(void) { - char * ans = malloc(sizeof(char) * strlen("Hello, World!")); - if (!ans) return NULL; - strcpy(ans,"Hello, World!"); - + char * ans = strdup("Hello, World!"); /* string is pointer of the first character */ return ans; }