ft_strdup

This commit is contained in:
Tanguy MAZE
2018-04-04 15:50:08 +02:00
parent 67b29782ae
commit 4930df1c01
3 changed files with 35 additions and 2 deletions

View File

@@ -6,7 +6,7 @@
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/04/04 10:51:59 by tmaze #+# #+# #
# Updated: 2018/04/04 15:08:39 by tmaze ### ########.fr #
# Updated: 2018/04/04 15:30:28 by tmaze ### ########.fr #
# #
#******************************************************************************#
@@ -18,6 +18,7 @@ NAME = libft.a
SRCS = \
ft_strlen.c \
ft_strdup.c \
ft_isalpha.c \
ft_isdigit.c \
ft_isalnum.c \

31
ft_strdup.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/03 16:33:35 by tmaze #+# #+# */
/* Updated: 2018/04/04 15:29:36 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
int i;
char *ret;
i = 0;
while (s1[i])
i++;
if ((ret = (char*)malloc(sizeof(char) * (i + 1))) != NULL)
{
ret[i] = '\0';
i = -1;
while (s1[++i])
ret[i] = s1[i];
}
return (ret);
}

View File

@@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/04 10:40:01 by tmaze #+# #+# */
/* Updated: 2018/04/04 10:44:30 by tmaze ### ########.fr */
/* Updated: 2018/04/04 15:30:00 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,7 @@
# define LIBFT_H
# include <string.h>
# include <stdlib.h>
/*
** fonctions obligatoires