Merge pull request #511 from lachgarlahcen/master

make strdup handle string alocation
This commit is contained in:
Stepfen Shawn 2020-05-29 22:57:29 +08:00 committed by GitHub
commit 773d9b21c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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