47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strdup.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/07/25 21:06:54 by adjoly #+# #+# */
|
|
/* Updated: 2023/08/03 16:38:19 by adjoly ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
int ft_strlen(char *str)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (str[i])
|
|
{
|
|
i++;
|
|
}
|
|
return (i);
|
|
}
|
|
|
|
char *ft_strdup(char *src)
|
|
{
|
|
int i;
|
|
char *dest;
|
|
int len;
|
|
|
|
i = 0;
|
|
len = ft_strlen(src);
|
|
dest = malloc(sizeof(char) * len);
|
|
if (dest == NULL)
|
|
return (NULL);
|
|
while (src[i])
|
|
{
|
|
dest[i] = src[i];
|
|
i++;
|
|
}
|
|
dest[i] = '\0';
|
|
return (dest);
|
|
}
|