commit d7c041eacf165e11776166dd728b77b897a9f334 Author: tosu Date: Fri Mar 31 02:43:22 2023 +0200 ft_strs_to_tab.c diff --git a/ex00/ft.h b/ex00/ft.h new file mode 100644 index 0000000..a4d3ecf --- /dev/null +++ b/ex00/ft.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/30 23:45:06 by tosuman #+# #+# */ +/* Updated: 2023/03/30 23:45:08 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +void ft_putchar(char c); +void ft_swap(int *a, int *b); +void ft_putstr(char *str); +int ft_strlen(char *str); +int ft_strcmp(char *s1, char *s2); + +#endif diff --git a/ex01/ft_boolean.h b/ex01/ft_boolean.h new file mode 100644 index 0000000..76be72b --- /dev/null +++ b/ex01/ft_boolean.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_boolean.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/30 23:47:26 by tosuman #+# #+# */ +/* Updated: 2023/03/30 23:47:26 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BOOLEAN_H +# define FT_BOOLEAN_H +# include +# define EVEN(nbr) (nbr % 2 == 0) +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" +# define FALSE 0 +# define TRUE 1 +# define SUCCESS 1 + +typedef char t_bool; + +#endif diff --git a/ex02/ft_abs.h b/ex02/ft_abs.h new file mode 100644 index 0000000..ce1165b --- /dev/null +++ b/ex02/ft_abs.h @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/31 00:06:36 by tosuman #+# #+# */ +/* Updated: 2023/03/31 00:06:37 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_ABS_H +# define FT_ABS_H +# define ABS(Value) (Value > 0 ? Value : -Value) +#endif diff --git a/ex03/ft_point.h b/ex03/ft_point.h new file mode 100644 index 0000000..cbcc0a0 --- /dev/null +++ b/ex03/ft_point.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_point.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/31 00:10:28 by tosuman #+# #+# */ +/* Updated: 2023/03/31 00:10:29 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_POINT_H +# define FT_POINT_H + +typedef struct s_point +{ + int x; + int y; +} t_point; + +#endif diff --git a/ex04/ft_strs_to_tab.c b/ex04/ft_strs_to_tab.c new file mode 100644 index 0000000..0a6a854 --- /dev/null +++ b/ex04/ft_strs_to_tab.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strs_to_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/31 00:56:37 by tosuman #+# #+# */ +/* Updated: 2023/03/31 00:56:38 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_stock_str.h" + +int ft_strlen(char *str) +{ + int size; + + size = 0; + while (*str++) + ++size; + return (size); +} + +char *ft_strcpy(char *str) +{ + char *copy; + int idx; + + copy = malloc(sizeof(char) * (ft_strlen(str) + 1)); + idx = 0; + while (*str) + copy[idx++] = *str++; + copy[idx] = 0; + return (copy); +} + +struct s_stock_str *ft_strs_to_tab(int ac, char **av) +{ + int idx; + t_stock_str *tab; + + tab = malloc(sizeof(t_stock_str) * (ac + 1)); + idx = -1; + while (++idx < ac) + { + tab[idx].size = ft_strlen(av[idx]); + tab[idx].str = av[idx]; + tab[idx].copy = ft_strcpy(av[idx]); + } + tab[idx].str = 0; + return (tab); +} + +/* //// +#include + +int main(void) +{ + char *strs[4]; + t_stock_str *tab; + + strs[0] = "First"; + strs[1] = "Second"; + strs[2] = "Third"; + tab = ft_strs_to_tab(3, strs); + printf("tab[0] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n", + tab[0].size, tab[0].str, tab[0].str, tab[0].copy, tab[0].copy); + printf("tab[1] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n", + tab[1].size, tab[1].str, tab[1].str, tab[1].copy, tab[1].copy); + printf("tab[2] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n", + tab[2].size, tab[2].str, tab[2].str, tab[2].copy, tab[2].copy); + printf("tab[3] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n", + tab[3].size, tab[3].str, tab[3].str, tab[3].copy, tab[3].copy); + return (0); +} +*/ ////