Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
7 changes: 4 additions & 3 deletions rush00/ft_putchar.c → C00/ex00/ft_putchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hsaadi <marvin@42quebec.com> +#+ +:+ +#+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/22 16:03:45 by hsaadi #+# #+# */
/* Updated: 2022/01/23 15:24:13 by hsaadi ### ########.fr */
/* Created: 2022/02/24 11:39:02 by loadjou #+# #+# */
/* Updated: 2022/02/24 11:41:19 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char c)
Expand Down
25 changes: 25 additions & 0 deletions C00/ex01/ft_print_alphabet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/24 11:42:24 by loadjou #+# #+# */
/* Updated: 2022/02/24 11:46:05 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_print_alphabet(void)
{
char c;

c = 'a';
while (c <= 'z')
{
write(1, &c, 1);
c++;
}
}
25 changes: 25 additions & 0 deletions C00/ex02/ft_print_reverse_alphabet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/24 11:53:34 by loadjou #+# #+# */
/* Updated: 2022/02/24 11:57:36 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_print_reverse_alphabet(void)
{
char c;

c = 'z';
while (c >= 'a')
{
write(1, &c, 1);
c--;
}
}
25 changes: 25 additions & 0 deletions C00/ex03/ft_print_numbers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 15:56:44 by loadjou #+# #+# */
/* Updated: 2022/02/24 11:59:00 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_print_numbers(void)
{
char i;

i = '0';
while (i <= '9')
{
write(1, &i, 1);
i++;
}
}
21 changes: 21 additions & 0 deletions C00/ex04/ft_is_negative.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_negative.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 16:04:52 by loadjou #+# #+# */
/* Updated: 2022/02/24 12:00:31 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_is_negative(int n)
{
if (n < 0)
write(1, "N", 1);
else
write(1, "P", 1);
}
51 changes: 51 additions & 0 deletions C00/ex05/ft_print_comb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 16:14:05 by loadjou #+# #+# */
/* Updated: 2022/03/17 16:55:41 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void escrever(char a, char b, char c)
{
write(1, &a, 1);
write(1, &b, 1);
write(1, &c, 1);
if (! (a == 55 && b == 56 && c == 57))
write(1, ", ", 2);
}

void while1(char a, char b, char c)
{
while (a < b < c && ! (a == 55 && b == 56 && c == 57))
{
escrever(a, b, c);
if (b == 56 && c == 57)
{
a++;
b = a + 1;
c = b + 1;
}
else if (c == 57 && b != 56)
{
b++;
c = b + 1;
}
else if (! (a == 55 && b == 56 && c == 57))
{
c++;
}
}
escrever(a, b, c);
}

void ft_print_comb(void)
{
while1(48, 49, 50);
}
66 changes: 66 additions & 0 deletions C00/ex06/ft_print_comb2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 19:22:57 by loadjou #+# #+# */
/* Updated: 2022/03/17 16:56:05 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void acrescimo(int num)
{
char ca;
char cb;

ca = 48;
cb = 48;
if (num <= 9)
{
cb = 48 + num;
}
else
{
ca = num / 10;
cb = (num - (ca * 10) + 48);
ca = ca + 48;
}
write(1, &ca, 1);
write(1, &cb, 1);
}

void escrever(int a)
{
if ((a + 1) < 99)
{
write(1, ",", 1);
write(1, " ", 1);
}
}

void while1(int a, int b)
{
while (b > a && a < 99)
{
acrescimo(a);
write(1, " ", 1);
acrescimo(b);
escrever(a);
if (b == 99)
{
a++;
b = a + 1;
}
else
b++;
}
}

void ft_print_comb2(void)
{
while1(0, 1);
}
42 changes: 42 additions & 0 deletions C00/ex07/ft_putnbr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/24 12:01:30 by loadjou #+# #+# */
/* Updated: 2022/02/24 12:02:01 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

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

void ft_putnbr(int nb)
{
long remp;

remp = nb;
if (remp >= 0 && remp < 10)
ft_putchar(remp + '0');
else if (remp < 0)
{
if (nb <= -2147483648)
write(1, "-2147483648", 11);
else
{
ft_putchar('-');
ft_putnbr(remp * (-1));
}
}
else
{
ft_putnbr(remp / 10);
ft_putnbr(remp % 10);
}
}
84 changes: 84 additions & 0 deletions C00/ex08/ft_print_combn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_combn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/17 17:05:57 by loadjou #+# #+# */
/* Updated: 2022/03/17 17:06:22 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>
#include <stdbool.h>

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

void ft_write_combo(int n, int holders[])
{
int index;
bool last;

index = 0;
while (index < n)
{
ft_putchar(48 + holders[index]);
index++;
}
index = n - 1;
last = true;
while (index >= 0)
{
if (holders[index] != 9 - (n - 1 - index))
{
last = false;
break ;
}
index--;
}
if (!last)
{
ft_putchar(',');
ft_putchar(' ');
}
}

void ft_print_combn_recursive(int n, int curr, int holders[], int st_index)
{
int index;
int max;

if (curr == n)
{
ft_write_combo(n, holders);
}
else
{
max = 10 - (n - curr);
index = st_index + 1;
while (index <= max)
{
holders[curr] = index;
ft_print_combn_recursive(n, curr + 1, holders, index);
index++;
}
}
}

void ft_print_combn(int n)
{
int holders[10];
int index;

index = 0;
while (index < n)
{
holders[index] = 0;
index++;
}
ft_print_combn_recursive(n, 0, holders, -1);
}
16 changes: 8 additions & 8 deletions c03/ex00/ft_strcmp.c → C03/ex00/ft_strcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hsaadi <marvin@42quebec.com> +#+ +:+ +#+ */
/* By: loadjou <marvin@42quebec.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/27 01:14:10 by hsaadi #+# #+# */
/* Updated: 2022/01/30 21:46:11 by hsaadi ### ########.fr */
/* Created: 2022/03/02 11:28:00 by loadjou #+# #+# */
/* Updated: 2022/03/03 15:34:04 by loadjou ### ########.fr */
/* */
/* ************************************************************************** */

int ft_strcmp(char *s1, char *s2)
{
int count;
int i;

count = 0;
while ((s1[count] && s2[count]) && (s1[count] == s2[count]))
i = 0;
while ((s1[i] && s2[i]) && (s1[i] == s2[i]))
{
count++;
i++;
}
return (s1[count] - s2[count]);
return (s1[i] - s2[i]);
}
Loading