mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
make strdup handle string alocation
This commit is contained in:
parent
807abcd0e8
commit
5f4727386f
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user