mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 21:27:16 +01:00
Piscine42
This commit is contained in:
43
C07/ex00/ft_strdup.c
Executable file
43
C07/ex00/ft_strdup.c
Executable file
@@ -0,0 +1,43 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user