42_C_PISCINE/C/c08/ex04/ft_strs_to_tab.c
Camille Chauvet 29ed24d567 init
2023-05-17 16:45:25 +00:00

56 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strs_to_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 09:28:54 by cchauvet #+# #+# */
/* Updated: 2022/07/27 19:53:38 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char *ft_strdup(char *src)
{
int i;
char *dest;
dest = malloc(sizeof(*dest) * ft_strlen(src));
i = 0;
while (src[i] != 0)
{
dest[i] = src[i];
i++;
}
dest[i] = 0;
return (dest);
}
t_stock_str *ft_strs_to_tab(int ac, char **av)
{
int i;
t_stock_str *tab;
tab = malloc(sizeof(*tab) * (ac + 1));
i = 0;
while (i < ac)
{
tab[i].size = ft_strlen(av[i]);
tab[i].str = av[i];
tab[i].copy = ft_strdup(av[i]);
i++;
}
tab[i].str = "";
return (tab);
}