Skip to content

Commit

Permalink
make strdup handle string alocation
Browse files Browse the repository at this point in the history
  • Loading branch information
lachgarlahcen committed Jan 26, 2020
1 parent 807abcd commit 5f47273
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions exercism/hello_world/hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 5f47273

Please sign in to comment.