Skip to content

Commit

Permalink
C Piscine C 00 - OK 100% (2019-11-27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanda Puchille pinha committed Dec 4, 2019
1 parent 0f03bef commit 0143c0e
Show file tree
Hide file tree
Showing 30 changed files with 556 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c_piscine_c_00/ex00/ft_putchar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/21 21:36:12 by apuchill #+# #+# */
/* Updated: 2019/11/21 22:03:21 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}
Binary file added c_piscine_c_00/ex00/t_a.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex00/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_putchar(char c);

int main(void)
{
ft_putchar('c');
return (0);
}
30 changes: 30 additions & 0 deletions c_piscine_c_00/ex01/ft_print_alphabet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/21 22:27:05 by apuchill #+# #+# */
/* Updated: 2019/11/21 22:41:03 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}

void ft_print_alphabet(void)
{
char alphabet;

alphabet = 'a';
while (alphabet <= 'z')
{
ft_putchar(alphabet);
alphabet++;
}
}
Binary file added c_piscine_c_00/ex01/t_a.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex01/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_print_alphabet(void);

int main(void)
{
ft_print_alphabet();
return (0);
}
30 changes: 30 additions & 0 deletions c_piscine_c_00/ex02/ft_print_reverse_alphabet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/21 23:38:44 by apuchill #+# #+# */
/* Updated: 2019/11/21 23:48:02 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}

void ft_print_reverse_alphabet(void)
{
char rev_alph;

rev_alph = 'z';
while (rev_alph >= 'a')
{
ft_putchar(rev_alph);
rev_alph--;
}
}
Binary file added c_piscine_c_00/ex02/t_a.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex02/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_print_reverse_alphabet(void);

int main(void)
{
ft_print_reverse_alphabet();
return (0);
}
30 changes: 30 additions & 0 deletions c_piscine_c_00/ex03/ft_print_numbers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/22 00:22:33 by apuchill #+# #+# */
/* Updated: 2019/11/22 00:31:18 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}

void ft_print_numbers(void)
{
char num;

num = '0';
while (num <= '9')
{
ft_putchar(num);
num++;
}
}
Binary file added c_piscine_c_00/ex03/t_a.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex03/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_print_numbers(void);

int main(void)
{
ft_print_numbers();
return 0;
}
30 changes: 30 additions & 0 deletions c_piscine_c_00/ex04/ft_is_negative.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_negative.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/22 00:42:03 by apuchill #+# #+# */
/* Updated: 2019/11/22 00:54:21 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_is_negative(int n)
{
char pos;
char neg;

pos = 'P';
neg = 'N';
if (n >= 0)
{
write(1, &pos, 1);
}
else
{
write(1, &neg, 1);
}
}
Binary file added c_piscine_c_00/ex04/t_a_neg.out
Binary file not shown.
Binary file added c_piscine_c_00/ex04/t_a_pos.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex04/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_is_negative(int n);

int main (void)
{
ft_is_negative(-2);
return (0);
}
48 changes: 48 additions & 0 deletions c_piscine_c_00/ex05/ft_print_comb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/22 20:42:11 by apuchill #+# #+# */
/* Updated: 2019/11/22 23:51:06 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_3num(char a, char b, char c)
{
write(1, &a, 1);
write(1, &b, 1);
write(1, &c, 1);
if (a != '7' || b != '8' || c != '9')
{
write(1, ", ", 2);
}
}

void ft_print_comb(void)
{
char d;
char e;
char f;

d = '0';
while (d <= '7')
{
e = d + 1;
while (e <= '8')
{
f = e + 1;
while (f <= '9')
{
ft_3num(d, e, f);
f++;
}
e++;
}
d++;
}
}
Binary file added c_piscine_c_00/ex05/t_a.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex05/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_print_comb(void);

int main(void)
{
ft_print_comb();
return(0);
}
64 changes: 64 additions & 0 deletions c_piscine_c_00/ex06/ft_print_comb2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/23 12:46:23 by apuchill #+# #+# */
/* Updated: 2019/11/24 15:30:20 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar2(char a, char b)
{
write(1, &a, 1);
write(1, &b, 1);
}

void ft_putint(int num, int max)
{
char ch_u;
char ch_d;

if (num <= 9)
{
ch_u = num + 48;
ft_putchar2('0', ch_u);
}
else if (num <= max)
{
ch_u = (num % 10) + 48;
ch_d = (num / 10) + 48;
ft_putchar2(ch_d, ch_u);
}
}

void ft_catint(int fir, int sec)
{
ft_putint(fir, 98);
write(1, " ", 1);
ft_putint(sec, 99);
if (fir != 98 || sec != 99)
ft_putchar2(',', ' ');
}

void ft_print_comb2(void)
{
int f;
int s;

f = 0;
while (f <= 98)
{
s = f + 1;
while (s <= 99)
{
ft_catint(f, s);
s++;
}
f++;
}
}
Binary file added c_piscine_c_00/ex06/t_a.out
Binary file not shown.
7 changes: 7 additions & 0 deletions c_piscine_c_00/ex06/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void ft_print_comb2(void);

int main(void)
{
ft_print_comb2();
return(0);
}
41 changes: 41 additions & 0 deletions c_piscine_c_00/ex07/ft_putnbr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/24 23:05:11 by apuchill #+# #+# */
/* Updated: 2019/11/24 23:52:20 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char a)
{
write(1, &a, 1);
}

void ft_putnbr(int nb)
{
if (nb == -2147483648)
{
ft_putchar('-');
ft_putchar('2');
nb = 147483648;
}
if (nb < 0)
{
ft_putchar('-');
nb *= -1;
}
if (nb < 10)
{
ft_putchar(nb + 48);
return ;
}
else
ft_putnbr(nb / 10);
ft_putnbr(nb % 10);
}
Binary file added c_piscine_c_00/ex07/t_a.out
Binary file not shown.
19 changes: 19 additions & 0 deletions c_piscine_c_00/ex07/t_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>

void ft_putnbr(int n);

int main(void)
{
printf(" (printed) should be 1");
ft_putnbr(1);
printf("\n (printed) should be 0");
ft_putnbr(0);
printf("\n (printed) should be -1");
ft_putnbr(-1);
printf("\n (printed) should be 2147483647");
ft_putnbr(2147483647);
printf("\n (printed) should be -21474836478");
ft_putnbr(-2147483648);
printf("\n");
return (0);
}
12 changes: 12 additions & 0 deletions c_piscine_c_00/ex07/t_main_argv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdlib.h>

void ft_putnbr(int nb);

int main(int argc, char *argv[])
{
char *av = argv[1];
int nbr = atoi(av);

ft_putnbr(nbr);
return(0);
}
Loading

1 comment on commit 0143c0e

@Sebwebswiss
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tnx

Please sign in to comment.