calloc and strdup
This commit is contained in:
28
ft_strdup.c
Normal file
28
ft_strdup.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/05 19:31:29 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/05 19:35:13 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
|
||||
dest = malloc(sizeof(char) *(ft_strlen(s) + 1));
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i++])
|
||||
dest[i] = s[i];
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
Reference in New Issue
Block a user