calloc and strdup

This commit is contained in:
David Gailleton
2025-11-05 19:37:02 +01:00
parent 697e044d7e
commit 86f9f05889
4 changed files with 60 additions and 2 deletions

28
ft_strdup.c Normal file
View 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);
}