make strdup handle string alocation

This commit is contained in:
lahcenlachgar 2020-01-26 07:06:43 -08:00
parent 807abcd0e8
commit 5f4727386f

View File

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