Add Ex0 to Ex3 (Ex4 and Ex5 is empty actually)

This commit is contained in:
lclerel- lclerel-
2026-03-16 18:24:39 +01:00
commit 52fc0e669d
6 changed files with 441 additions and 0 deletions

72
ex0/ft_strdup.c Normal file
View File

@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/16 14:01:43 by lclerel- #+# #+# */
/* Updated: 2026/03/16 16:31:19 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);
}*/