1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
42-1st-piscine/C08/ex04/ft_strs_to_tab.c
2023-08-06 20:12:38 +02:00

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);
}