Skip to content

Commit

Permalink
C Piscine C 06 - OK 100% (2019-12-11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanda Puchille pinha committed Dec 13, 2019
1 parent 10bb0ea commit cdc3d20
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 0 deletions.
30 changes: 30 additions & 0 deletions c_piscine_c_06/ex00/ft_print_program_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/09 14:10:42 by apuchill #+# #+# */
/* Updated: 2019/12/09 18:28:13 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

int main(int argc, char **argv)
{
int c;

c = 0;
if (argc > 0)
{
while (argv[0][c] != '\0')
{
write(1, &argv[0][c], 1);
c++;
}
write(1, "\n", 1);
}
return (0);
}
Binary file added c_piscine_c_06/ex00/t_a.out
Binary file not shown.
37 changes: 37 additions & 0 deletions c_piscine_c_06/ex01/ft_print_params.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/09 14:20:32 by apuchill #+# #+# */
/* Updated: 2019/12/09 18:28:30 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

int main(int argc, char **argv)
{
int c;
int d;

c = 1;
d = 0;
if (argc > 1)
{
while (c < argc)
{
d = 0;
while (argv[c][d] != '\0')
{
write(1, &argv[c][d], 1);
d++;
}
write(1, "\n", 1);
c++;
}
}
return (0);
}
Binary file added c_piscine_c_06/ex01/t_a.out
Binary file not shown.
37 changes: 37 additions & 0 deletions c_piscine_c_06/ex02/ft_rev_params.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/09 14:20:32 by apuchill #+# #+# */
/* Updated: 2019/12/09 18:28:41 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

int main(int argc, char **argv)
{
int c;
int d;

c = argc - 1;
d = 0;
if (argc > 1)
{
while (c > 0)
{
d = 0;
while (argv[c][d] != '\0')
{
write(1, &argv[c][d], 1);
d++;
}
write(1, "\n", 1);
c--;
}
}
return (0);
}
Binary file added c_piscine_c_06/ex02/t_a.out
Binary file not shown.
73 changes: 73 additions & 0 deletions c_piscine_c_06/ex03/ft_sort_params.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/09 16:33:03 by apuchill #+# #+# */
/* Updated: 2019/12/09 18:28:55 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putstr(const char *str)
{
int c;

c = 0;
while (str[c] != '\0')
{
write(1, &str[c], 1);
c++;
}
write(1, "\n", 1);
}

int ft_strcmp(const char *s1, const char *s2)
{
int c;

c = 0;
while ((s1[c] == s2[c]) && (s1[c] != '\0') && (s2[c] != '\0'))
c++;
return (s1[c] - s2[c]);
}

void ft_swap(int *a, int *b)
{
int aux;

aux = *a;
*a = *b;
*b = aux;
}

int main(int argc, const char **argv)
{
int qty;
int c;
int d;
int arg[argc];

qty = 1;
c = 1;
while (qty < argc)
{
arg[qty] = qty;
qty++;
}
while (c < argc)
{
d = c;
while (d < argc)
{
if (ft_strcmp(argv[arg[c]], argv[arg[d]]) > 0)
ft_swap(&arg[c], &arg[d]);
d++;
}
ft_putstr(argv[arg[c++]]);
}
return (0);
}
Binary file added c_piscine_c_06/ex03/t_a.out
Binary file not shown.

0 comments on commit cdc3d20

Please sign in to comment.