mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2025-12-16 05:58:07 +01:00
44 lines
1.2 KiB
C
Executable File
44 lines
1.2 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strdup.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/14 13:53:46 by fgras-ca #+# #+# */
|
|
/* Updated: 2022/12/18 08:21:14 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
|
|
int ft_strlen(char *str)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (str[i])
|
|
i++;
|
|
return (i);
|
|
}
|
|
|
|
char *ft_strdup(char *src)
|
|
{
|
|
char *copy;
|
|
int i;
|
|
|
|
i = 0;
|
|
copy = (char *) malloc(sizeof(char) * (ft_strlen(src) + 1));
|
|
if (copy == 0)
|
|
{
|
|
return (0);
|
|
}
|
|
while (src [i])
|
|
{
|
|
copy[i] = src[i];
|
|
i++;
|
|
}
|
|
copy[i] = '\0';
|
|
return (copy);
|
|
}
|