68 lines
1.6 KiB
C
68 lines
1.6 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_strs_to_tab.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2022/08/04 10:52:25 by ajoly #+# #+# */
|
||
|
/* Updated: 2022/08/04 21:46:09 by ajoly ### ########.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;
|
||
|
|
||
|
i = 0;
|
||
|
while (src[i])
|
||
|
i++;
|
||
|
dest = malloc(i + 1);
|
||
|
i = 0;
|
||
|
while (src[i])
|
||
|
{
|
||
|
dest[i] = src[i];
|
||
|
i++;
|
||
|
}
|
||
|
dest[i] = '\0';
|
||
|
return (dest);
|
||
|
}
|
||
|
|
||
|
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
|
||
|
{
|
||
|
t_stock_str *tab;
|
||
|
int i;
|
||
|
|
||
|
tab = malloc(sizeof(t_stock_str) * (ac + 1));
|
||
|
if (tab == NULL)
|
||
|
return (NULL);
|
||
|
i = 0;
|
||
|
while (i < ac)
|
||
|
{
|
||
|
tab[i].str = av[i];
|
||
|
tab[i].copy = ft_strdup(tab[i].str);
|
||
|
tab[i].size = ft_strlen(av[i]);
|
||
|
i++;
|
||
|
}
|
||
|
tab[i].str = 0;
|
||
|
tab[i].size = 0;
|
||
|
tab[i].copy = 0;
|
||
|
return (tab);
|
||
|
}
|