1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
42-2nd-piscine/C07/ex00/ft_strdup.c
2023-08-03 23:16:27 +02:00

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);
}