46 lines
1.4 KiB
C
46 lines
1.4 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"
|
|
|
|
static int ft_strslen(char **src)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (src[i])
|
|
i++;
|
|
return (i);
|
|
}
|
|
|
|
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);
|
|
}
|