philosopher/libft/ft_strdups.c
2023-03-06 17:38:20 +01:00

36 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdups.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */
/* Updated: 2022/12/29 18:05:24 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strdups(char **src)
{
char **src_copy;
int x;
int y;
src_copy = ft_calloc(ft_strslen(src) + 1, (sizeof(char *)));
if (src_copy == NULL)
return (NULL);
x = -1;
while (src[++x])
{
src_copy[x] = ft_calloc(ft_strlen(src[x]) + 1, 1);
y = -1;
while (src[x][++y])
src_copy[x][y] = src[x][y];
src_copy[x][y] = '\0';
}
src_copy[x] = NULL;
return (src_copy);
}