Files
C-Memory-Management/ex0/ft_strdup.c
lclerel- lclerel- 28fb6502a2 Push Exos
2026-03-19 15:15:53 +01:00

73 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/16 14:01:43 by lclerel- #+# #+# */
/* Updated: 2026/03/19 11:37:45 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdlib.h>
char *ft_strdup(char *src)
{
int i;
int len;
char *dst;
i = 0;
len = 0;
while (src[len])
{
len++;
}
dst = malloc(sizeof(char) * (len + 1));
if (dst == NULL)
{
return (NULL);
}
while (i < len)
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}
/*
void ft_putchar(char chara)
{
write(1, &chara, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
ft_putchar(str[i]);
i++;
}
}
int main(void)
{
char *dest;
dest = ft_strdup("TestTest");
if (dest == NULL)
{
return (1);
}
ft_putstr(dest);
free(dest);
}*/