65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* s_stock_str.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */
|
|
/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.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_strcopy(char *str)
|
|
{
|
|
char *result;
|
|
int i;
|
|
int len;
|
|
|
|
len = ft_strlen(str);
|
|
result = (char *) malloc((len + 1) * sizeof(char));
|
|
i = 0;
|
|
while (str[i] != '\0')
|
|
{
|
|
result[i] = str[i];
|
|
i++;
|
|
}
|
|
result[i] = '\0';
|
|
return (result);
|
|
}
|
|
|
|
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
|
|
{
|
|
int i;
|
|
t_stock_str *result;
|
|
|
|
result = (t_stock_str *) malloc((ac + 1) * sizeof(result));
|
|
if (result == NULL)
|
|
return (NULL);
|
|
i = 0;
|
|
while (i < ac)
|
|
{
|
|
result[i].size = ft_strlen(av[i]);
|
|
result[i].str = av[i];
|
|
result[i].copy = ft_strcopy(av[i]);
|
|
i++;
|
|
}
|
|
result[i].size = 0;
|
|
result[i].str = 0;
|
|
result[i].copy = 0;
|
|
return ((struct s_stock_str*) result);
|
|
}
|