1
0
libft_new/ft_strdup.c

34 lines
1.1 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 22:57:39 by adjoly #+# #+# */
/* Updated: 2023/11/03 23:08:23 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
int i;
char *result;
int len;
i = 0;
len = ft_strlen(s);
result = malloc(sizeof(char) * len);
if (result == NULL)
return (NULL);
while (s[i])
{
result[i] = s[i];
i++;
}
result[i] = '\0';
return (result);
}