diff --git a/ex01/ft_print_params.c b/ex01/ft_print_params.c new file mode 100644 index 0000000..7aa3ef4 --- /dev/null +++ b/ex01/ft_print_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/30 18:09:30 by tosuman #+# #+# */ +/* Updated: 2023/03/30 18:09:31 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_printstr(char *str) +{ + while (*str) + write(1, str++, 1); + write(1, "\n", 1); +} + +/* //// +int main(int argc, char **argv) +{ + int i; + + i = 0; + while (++i < argc) + ft_printstr(argv[i]); + return (0); +} +*/ //// diff --git a/ex02/ft_rev_params.c b/ex02/ft_rev_params.c new file mode 100644 index 0000000..5e3cc0f --- /dev/null +++ b/ex02/ft_rev_params.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/30 18:12:39 by tosuman #+# #+# */ +/* Updated: 2023/03/30 18:12:40 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_printstr(char *str) +{ + while (*str) + write(1, str++, 1); + write(1, "\n", 1); +} + +/* //// +int main(int argc, char **argv) +{ + while (--argc) + ft_printstr(argv[argc]); + return (0); +} +*/ //// diff --git a/ex03/ft_sort_params.c b/ex03/ft_sort_params.c new file mode 100644 index 0000000..b5e6a83 --- /dev/null +++ b/ex03/ft_sort_params.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/30 18:58:16 by tosuman #+# #+# */ +/* Updated: 2023/03/30 18:58:16 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_printstr(char *str) +{ + while (*str) + write(1, str++, 1); + write(1, "\n", 1); +} + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + ++s1; + ++s2; + } + return (*s1 - *s2); +} + +void swap_reset(int *counter, char **p1, char **p2) +{ + char *tmp; + + *counter = -1; + tmp = *p1; + *p1 = *p2; + *p2 = tmp; +} + +void ft_sort_str_tab(int size, char **tab) +{ + int idx; + + ++size; + idx = -1; + while (--size) + while (++idx < size - 1) + if (ft_strcmp(tab[idx], tab[idx + 1]) < 0) + swap_reset(&idx, &tab[idx], &tab[idx + 1]); +} + +int main(int argc, char **argv) +{ + ft_sort_str_tab(--argc, ++argv); + while (argc--) + ft_printstr(argv[argc]); + return (0); +}