Up until ex03
This commit is contained in:
parent
36db12724f
commit
021d4b8429
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/30 18:09:30 by tosuman #+# #+# */
|
||||
/* Updated: 2023/03/30 18:09:31 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
||||
*/ ////
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_rev_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/30 18:12:39 by tosuman #+# #+# */
|
||||
/* Updated: 2023/03/30 18:12:40 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
||||
*/ ////
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sort_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/30 18:58:16 by tosuman #+# #+# */
|
||||
/* Updated: 2023/03/30 18:58:16 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue