59 lines
1.5 KiB
C
59 lines
1.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strs_to_tab.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/07/27 09:28:54 by cchauvet #+# #+# */
|
|
/* Updated: 2022/08/03 17:27:47 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include "ft_stock_str.h"
|
|
|
|
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);
|
|
}
|