ft_strdup
Subject
STRDUP(3) (simplified)
NAME
strdup -- save a copy of a string
SYNOPSIS
char *strdup(const char *s1);
DESCRIPTION
The strdup() function allocates sufficient memory for a copy of the string s1, does the copy, and returns a pointer to it. The pointer may subsequently be used as an argument to the function free(3).
If insufficient memory is available, NULL is returned and errno is set to ENOMEM.Understandable explanation
Hints
char *ft_strdup(const char *s1)
{
/* use malloc to allocate enough space for s1
* we will have to copy it completely
* so we need enough space for it
*/
/* loop over s1 and copy each character in the new string you
* just allocated
*/
/* return the allocated and copied string */
}Commented solution
Last updated