From dac092452ee398be7578b5219e71c67228cbe914 Mon Sep 17 00:00:00 2001 From: Baco Date: Wed, 25 Aug 2021 13:49:16 +0200 Subject: [PATCH] commit --- C_08/git/ex04/ft_stock_str.h | 25 +++++++++---- C_08/git/ex04/ft_strs_to_tab.c | 64 ++++++++++++++++++++++++++++------ C_08/git/ex04/main.c | 15 +++++--- 3 files changed, 82 insertions(+), 22 deletions(-) diff --git a/C_08/git/ex04/ft_stock_str.h b/C_08/git/ex04/ft_stock_str.h index c35e1b9..24e3d31 100644 --- a/C_08/git/ex04/ft_stock_str.h +++ b/C_08/git/ex04/ft_stock_str.h @@ -1,9 +1,20 @@ -#ifndef FT_STOCK__STR_H -# define FT_STOCK__STR_H -typedef struct s_stock_str +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_stock_str.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ +#ifndef FT_STOCK_STR_H +# define FT_STOCK_STR_H +typedef struct s_stock_str { - int size; - char *str; - char *copy; -} t_stock_str; + int size; + char *str; + char *copy; +} t_stock_str; #endif diff --git a/C_08/git/ex04/ft_strs_to_tab.c b/C_08/git/ex04/ft_strs_to_tab.c index 4ebbbc1..6a056fc 100644 --- a/C_08/git/ex04/ft_strs_to_tab.c +++ b/C_08/git/ex04/ft_strs_to_tab.c @@ -1,22 +1,64 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_point.h :+: :+: :+: */ +/* s_stock_str.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gbaconni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */ -/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */ +/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef FT_POINT_H -# define FT_POINT_H +#include +#include "ft_stock_str.h" -typedef struct s_point +int ft_strlen(char *str) { - int x; - int y; -} t_point; -void set_point(t_point *point); -#endif + 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); +} diff --git a/C_08/git/ex04/main.c b/C_08/git/ex04/main.c index 8f46011..c31411e 100644 --- a/C_08/git/ex04/main.c +++ b/C_08/git/ex04/main.c @@ -10,16 +10,23 @@ /* */ /* ************************************************************************** */ +#include #include "ft_stock_str.h" struct s_stock_str *ft_strs_to_tab(int ac, char **av); -int main(void) +int main(int argc, char **argv) { t_stock_str *result; - char **av; - int ac; + int i; - result = ft_strs_to_tab(ac, av) + (void) result; + result = ft_strs_to_tab(argc, argv); + i = 0; + while (result[i].size > 0) + { + printf("result[%d] = { size=%d, str=%s, copy=%s\n}", i, result[i].size, result[i].str, result[i].copy); + i++; + } return (0); }