ft_strdup
This commit is contained in:
3
Makefile
3
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
|
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2018/04/04 10:51:59 by tmaze #+# #+# #
|
# 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 = \
|
SRCS = \
|
||||||
ft_strlen.c \
|
ft_strlen.c \
|
||||||
|
ft_strdup.c \
|
||||||
ft_isalpha.c \
|
ft_isalpha.c \
|
||||||
ft_isdigit.c \
|
ft_isdigit.c \
|
||||||
ft_isalnum.c \
|
ft_isalnum.c \
|
||||||
|
31
ft_strdup.c
Normal file
31
ft_strdup.c
Normal 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);
|
||||||
|
}
|
3
libft.h
3
libft.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/04 10:40:01 by tmaze #+# #+# */
|
/* 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
|
# define LIBFT_H
|
||||||
|
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** fonctions obligatoires
|
** fonctions obligatoires
|
||||||
|
Reference in New Issue
Block a user