/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* 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_puts(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_puts(argv[argc]); return (0); }