Add Ex0 to Ex3 (Ex4 and Ex5 is empty actually)
This commit is contained in:
72
ex0/ft_strdup.c
Normal file
72
ex0/ft_strdup.c
Normal 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);
|
||||
}*/
|
||||
Reference in New Issue
Block a user