Skip to content

Commit 773d9b2

Browse files
authored
Merge pull request TheAlgorithms#511 from lachgarlahcen/master
make strdup handle string alocation
2 parents c3a1244 + 5f47273 commit 773d9b2

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

exercism/hello_world/hello_world.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
const char *hello(void)
66
{
7-
char * ans = malloc(sizeof(char) * strlen("Hello, World!"));
8-
if (!ans) return NULL;
9-
strcpy(ans,"Hello, World!");
10-
7+
char * ans = strdup("Hello, World!");
118
/* string is pointer of the first character */
129
return ans;
1310
}

0 commit comments

Comments
 (0)