Update Final 42
This commit is contained in:
Submodule Memory Management/C-Function-Pointers deleted from cff0d52035
@@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_foreach.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/12 09:38:54 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/17 11:36:19 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_foreach(int *tab, int length, void (*f)(int))
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
f(tab[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/*
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int tab[4] = {1, 8, 9, 6};
|
||||
int i;
|
||||
int length;
|
||||
i = 0;
|
||||
length = 4;
|
||||
|
||||
write(1, "Test avec tableau de 4, avec valeur 1 8 9 6 : ", 46);
|
||||
write(1, "\n", 1);
|
||||
while (i < length)
|
||||
{
|
||||
ft_putnbr(tab[i]);
|
||||
i++;
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
}*/
|
||||
@@ -0,0 +1,80 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/12 09:41:12 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/17 11:36:53 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_map(int *tab, int length, int (*f)(int))
|
||||
{
|
||||
int i;
|
||||
int *tab2;
|
||||
|
||||
tab2 = malloc(sizeof(int) * length);
|
||||
i = 0;
|
||||
if (!tab2)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
while (i < length)
|
||||
{
|
||||
tab2[i] = f(tab[i]);
|
||||
i++;
|
||||
}
|
||||
return (tab2);
|
||||
}
|
||||
/*
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}
|
||||
|
||||
int ft_carre(int n)
|
||||
{
|
||||
return (n * n);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int tab[4] = {1, 8, 9, 6};
|
||||
int *result = ft_map(tab, 4, &ft_carre);
|
||||
int i;
|
||||
int length;
|
||||
|
||||
i = 0;
|
||||
length = 4;
|
||||
|
||||
write(1, "Test avec tableau de 4, avec valeur 1 8 9 6 : ", 46);
|
||||
write(1, "\n", 1);
|
||||
while (i < length)
|
||||
{
|
||||
ft_putnbr(result[i]);
|
||||
i++;
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
}*/
|
||||
@@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_any.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/12 11:29:41 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/17 11:37:55 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_any(char **tab, int (*f)(char*))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
{
|
||||
if (f(tab[i]) != 0)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
/*
|
||||
int s_check(char *s)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (s[i] == 'S')
|
||||
{
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *tab[] = {"Test", "1234", "Test56", "singesavant", NULL};
|
||||
int result;
|
||||
|
||||
result = ft_any(tab, &s_check);
|
||||
if (result == 1)
|
||||
{
|
||||
write(1, "Un mot a ete trouver\n", 22);
|
||||
}
|
||||
else
|
||||
{
|
||||
write(1, "Rien trouver.\n", 14);
|
||||
}
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,96 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_count_if.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/12 11:54:32 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 11:56:49 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_count_if(char **tab, int length, int (*f)(char*))
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
if (!tab || !f)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
while (i < length)
|
||||
{
|
||||
if (f(tab[i]) != 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
/*int len_check(char *s)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (s[i])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if (i > 3)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *tab[] = {"Test", "1234", "Test56", "singesavant", NULL};
|
||||
int result;
|
||||
int length = 0;
|
||||
|
||||
while (tab[length] != NULL)
|
||||
{
|
||||
length++;
|
||||
}
|
||||
result = ft_count_if(tab, length, &len_check);
|
||||
if (result > 1)
|
||||
{
|
||||
write(1, "Plusieurs mots ont ete trouver\n", 31);
|
||||
write(1, "Nombre Total : ", 15);
|
||||
ft_putnbr(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
write(1, "Rien trouver.\n", 14);
|
||||
}
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,105 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_sort.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/13 14:01:47 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/17 11:39:02 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_is_sort(int *tab, int length, int (*f)(int, int))
|
||||
{
|
||||
int i;
|
||||
int cs;
|
||||
int ds;
|
||||
|
||||
i = 0;
|
||||
cs = 1;
|
||||
ds = 1;
|
||||
if (length <= 1)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
while (i < length - 1)
|
||||
{
|
||||
if (f(tab[i], tab[i + 1]) > 0)
|
||||
{
|
||||
cs = 0;
|
||||
}
|
||||
if (f(tab[i], tab[i + 1]) < 0)
|
||||
{
|
||||
ds = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (cs || ds);
|
||||
}
|
||||
|
||||
/*
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}
|
||||
|
||||
int ft_compare(int a, int b)
|
||||
{
|
||||
return (a - b);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int croiss[] = {1, 2, 3, 4, 5, 6, 6, 7};
|
||||
int decroiss[] = {7, 6, 6, 5, 4, 3, 2, 1};
|
||||
int pas_trie[] = {1, 2, 3, 5, 6, 7, 6, 9};
|
||||
int neg[] = {-1, -12, 11, -19};
|
||||
|
||||
write(1, "Test Croissant > (1, 2, 3, 4, 5, 6, 6, 7) : ", 44);
|
||||
if (ft_is_sort(croiss, 8, &ft_compare) == 1)
|
||||
write(1, "Ok :3 (Trié)\n", 14);
|
||||
else
|
||||
write(1, "Not ok (Pas trié)\n", 19);
|
||||
|
||||
// Test 2 : Décroissant
|
||||
write(1, "Test Decroissant > (7, 6, 6, 5, 4, 3, 2, 1) : ", 46);
|
||||
if (ft_is_sort(decroiss, 8, &ft_compare) == 1)
|
||||
write(1, "Ok :3 (Trié)\n", 14);
|
||||
else
|
||||
write(1, "Not ok (Pas trié)\n", 19);
|
||||
|
||||
// Test 3 : Pas trié
|
||||
write(1, "Test Pas trier > (1, 2, 3, 5, 6, 7, 6, 9) : ", 44);
|
||||
if (ft_is_sort(pas_trie, 8, &ft_compare) == 1)
|
||||
write(1, "Ok :3 (Trié)\n", 14);
|
||||
else
|
||||
write(1, "Not ok (Pas trié)\n", 19);
|
||||
|
||||
// Test 4 : Negatif
|
||||
write(1, "Test avec negatif > (-1, -12, 11, -19) : ", 42);
|
||||
if (ft_is_sort(neg, 4, &ft_compare) == 1)
|
||||
write(1, "Ok :3 (Trié)\n", 14);
|
||||
else
|
||||
write(1, "Not ok (Pas trié)\n", 19);
|
||||
return (0);
|
||||
}*/
|
||||
Submodule Memory Management/C-Memory-Management deleted from 3841fc1ff0
@@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/16 14:01:43 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/23 10:11:54 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strdup(char *src)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
char *dst;
|
||||
|
||||
i = 0;
|
||||
len = 0;
|
||||
if (src == NULL)
|
||||
return (NULL);
|
||||
while (src[len])
|
||||
len++;
|
||||
dst = malloc(sizeof(char) * (len + 1));
|
||||
if (dst == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
while (i < len)
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = '\0';
|
||||
return (dst);
|
||||
}
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *dest;
|
||||
|
||||
dest = ft_strdup(NULL);
|
||||
|
||||
if (dest == NULL)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
ft_putstr(dest);
|
||||
free(dest);
|
||||
}*/
|
||||
@@ -0,0 +1,116 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/16 14:44:51 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 14:05:04 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int *ft_range(int min, int max)
|
||||
{
|
||||
int *range;
|
||||
int i;
|
||||
int size;
|
||||
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
size = max - min;
|
||||
range = malloc(sizeof(int) * size);
|
||||
if (!range)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
while (i < size)
|
||||
{
|
||||
range[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
return (range);
|
||||
}
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int *tab;
|
||||
int min = 2;
|
||||
int max = 10;
|
||||
int i = 0;
|
||||
|
||||
// TEST 1 : Cas Normal
|
||||
tab = ft_range(min, max);
|
||||
write(1, "/~~~Test 1~~~\\\n", 15);
|
||||
write(1, "> Min : ", 8);
|
||||
ft_putnbr(min);
|
||||
write(1, " <\n> Max : ", 11);
|
||||
ft_putnbr(max);
|
||||
write(1, " <\n> Resultat : ", 16);
|
||||
if (!tab)
|
||||
write(1, "NULL", 4);
|
||||
else
|
||||
{
|
||||
while (i < (max - min))
|
||||
{
|
||||
ft_putnbr(tab[i]);
|
||||
if (i < (max - min - 1))
|
||||
write(1, ", ", 2);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
write(1, " <\n\\~~~Test 1~~~/\n\n", 18);
|
||||
free(tab);
|
||||
// TEST 2 : Cas Erreur (Min > Max)
|
||||
int min_err = 9;
|
||||
int max_err = 2;
|
||||
int *tab_err = ft_range(min_err, max_err);
|
||||
|
||||
write(1, "/~~~Test 2~~~\\\n", 15);
|
||||
write(1, "> Min : ", 8);
|
||||
ft_putnbr(min_err);
|
||||
write(1, " <\n> Max : ", 11);
|
||||
ft_putnbr(max_err);
|
||||
write(1, " <\n> Resultat : ", 16);
|
||||
if (!tab_err)
|
||||
write(1, "NULL (OK)", 9);
|
||||
else
|
||||
write(1, "ERREUR : Devrait etre NULL", 26);
|
||||
write(1, " <\n\\~~~Test 2~~~/\n", 18);
|
||||
if (tab_err)
|
||||
free(tab_err);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/16 16:07:45 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 19:23:18 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
int i;
|
||||
int *tab;
|
||||
int size;
|
||||
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
*range = NULL;
|
||||
return (0);
|
||||
}
|
||||
size = max - min;
|
||||
tab = malloc(sizeof(int) * size);
|
||||
if (!tab)
|
||||
{
|
||||
*range = NULL;
|
||||
return (-1);
|
||||
}
|
||||
while (i < size)
|
||||
{
|
||||
tab[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
*range = tab;
|
||||
return (size);
|
||||
}
|
||||
/*
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int *tab;
|
||||
int min = 2;
|
||||
int max = 10;
|
||||
int size;
|
||||
// Integers pour les errors
|
||||
int max_err = 2;
|
||||
int min_err = 9;
|
||||
int *tab_err;
|
||||
int size_err;
|
||||
// Integers pour le 3eme Test
|
||||
int max2 = -5;
|
||||
int min2 = -1;
|
||||
int *tab2;
|
||||
int size2;
|
||||
size_err = ft_ultimate_range(&tab_err ,min_err, max_err);
|
||||
size = ft_ultimate_range(&tab, min, max);
|
||||
size2 = ft_ultimate_range(&tab2, min2, max2);
|
||||
if (size == -1)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
// Test 1, Test Min 2 Max 10.
|
||||
write(1, "/~~~Test 1~~~\\ \n", 16);
|
||||
write(1, "> Min : ", 8);
|
||||
ft_putnbr(min);
|
||||
write(1, " <\n> Max : ", 11);
|
||||
ft_putnbr(max);
|
||||
write(1, " <\n> Resultat : ", 17);
|
||||
ft_putnbr(size);
|
||||
write(1, " <\n\\~~~Test 1~~~/", 18);
|
||||
ft_putchar('\n');
|
||||
// Test 2, Test Min 9 Max 2 (Return Error)
|
||||
write(1, "/~~~Test 2~~~\\ \n", 16);
|
||||
write(1, "> Min : ", 8);
|
||||
ft_putnbr(min_err);
|
||||
write(1, " <\n> Max : ", 11);
|
||||
ft_putnbr(max_err);
|
||||
write(1, " <\n> Resultat : ", 17);
|
||||
ft_putnbr(size_err);
|
||||
write(1, " <\n\\~~~Test 2~~~/", 18);
|
||||
ft_putchar('\n');
|
||||
// Test 3, Test Min -1 Max -5.
|
||||
write(1, "/~~~Test 3~~~\\ \n", 16);
|
||||
write(1, "> Min : ", 8);
|
||||
ft_putnbr(min2);
|
||||
write(1, " <\n> Max : ", 11);
|
||||
ft_putnbr(max2);
|
||||
write(1, " <\n> Resultat : ", 17);
|
||||
ft_putnbr(size2);
|
||||
write(1, " <\n\\~~~Test 3~~~/", 18);
|
||||
ft_putchar('\n');
|
||||
free(tab);
|
||||
}*/
|
||||
@@ -0,0 +1,133 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/16 16:37:56 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 19:24:56 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int get_total_len(int size, char **strs, char *sep)
|
||||
{
|
||||
int i;
|
||||
int total;
|
||||
|
||||
i = 0;
|
||||
total = 0;
|
||||
while (i < size)
|
||||
{
|
||||
total = total + ft_strlen(strs[i]);
|
||||
if (i < size - 1)
|
||||
{
|
||||
total = total + ft_strlen(sep);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (total);
|
||||
}
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (dest[i])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
while (src[j])
|
||||
{
|
||||
dest[i + j] = src[j];
|
||||
j++;
|
||||
}
|
||||
dest[i + j] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
char *ft_strjoin(int size, char **strs, char *sep)
|
||||
{
|
||||
char *res;
|
||||
int i;
|
||||
int len;
|
||||
|
||||
i = 0;
|
||||
if (size == 0)
|
||||
{
|
||||
res = malloc(1);
|
||||
if (res)
|
||||
res[0] = '\0';
|
||||
return (res);
|
||||
}
|
||||
len = get_total_len(size, strs, sep);
|
||||
res = malloc(sizeof(char) * (len + 1));
|
||||
if (!res)
|
||||
return (NULL);
|
||||
res[0] = '\0';
|
||||
while (i < size)
|
||||
{
|
||||
ft_strcat(res, strs[i]);
|
||||
if (i < size - 1)
|
||||
ft_strcat(res, sep);
|
||||
i++;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
/*
|
||||
void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *tab[5];
|
||||
char *result;
|
||||
char *space;
|
||||
|
||||
tab[0] = "Salut";
|
||||
tab[1] = "Je";
|
||||
tab[2] = "Suis";
|
||||
tab[3] = "Lumi";
|
||||
tab[4] = "!";
|
||||
space = " ";
|
||||
result = ft_strjoin(5, tab, space);
|
||||
if (result)
|
||||
{
|
||||
ft_putstr(result);
|
||||
ft_putstr("\n");
|
||||
free(result);
|
||||
}
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,200 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_convert_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/17 14:20:07 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 11:36:19 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_putstr(char *str);
|
||||
|
||||
int ft_strlen(char *str);
|
||||
|
||||
int ft_nbrlen(long nbr, int base_size);
|
||||
|
||||
int check_base(char *base);
|
||||
|
||||
int ft_index(char c, char *base)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (base[i])
|
||||
{
|
||||
if (base[i] == c)
|
||||
return (i);
|
||||
i++;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int ft_atoi_base(char *str, char *base)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
long res;
|
||||
|
||||
res = 0;
|
||||
i = 0;
|
||||
sign = 1;
|
||||
while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13))
|
||||
i++;
|
||||
while (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i++] == '-')
|
||||
sign *= -1;
|
||||
}
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] && ft_index(str[i], base) != -1)
|
||||
{
|
||||
res = (res * ft_strlen(base)) + ft_index(str[i], base);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (res * sign);
|
||||
}
|
||||
|
||||
void ft_populate_res(char *res, long n, char *base_to, int size)
|
||||
{
|
||||
int base_len;
|
||||
|
||||
base_len = ft_strlen(base_to);
|
||||
res[size] = '\0';
|
||||
if (n == 0)
|
||||
res[0] = base_to[0];
|
||||
if (n < 0)
|
||||
{
|
||||
res[0] = '-';
|
||||
n = -n;
|
||||
}
|
||||
while (n > 0)
|
||||
{
|
||||
res[size - 1] = base_to[n % base_len];
|
||||
n /= base_len;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
char *ft_convert_base(char *nbr, char *base_from, char *base_to)
|
||||
{
|
||||
long n;
|
||||
char *res;
|
||||
int size;
|
||||
|
||||
if (!nbr || !base_from || !base_to)
|
||||
return (NULL);
|
||||
if (!check_base(base_from) || !check_base(base_to))
|
||||
return (NULL);
|
||||
n = ft_atoi_base(nbr, base_from);
|
||||
size = ft_nbrlen(n, ft_strlen(base_to));
|
||||
res = malloc(sizeof(char) * (size + 1));
|
||||
if (!res)
|
||||
return (NULL);
|
||||
ft_populate_res(res, n, base_to, size);
|
||||
return (res);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *result;
|
||||
char *hex;
|
||||
char *bin;
|
||||
char *dec;
|
||||
char *vif;
|
||||
|
||||
hex = "0123456789abcdef";
|
||||
dec = "0123456789";
|
||||
bin = "01";
|
||||
vif = "poneyvif";
|
||||
// Test 1 : 42 > Dec to Bin
|
||||
ft_putstr("Test avec 42 | ");
|
||||
ft_putstr("Base From : Decimal (Base 10), Base To : Binary (Base 2)");
|
||||
write(1, "\n", 1);
|
||||
result = ft_convert_base("42", dec, bin);
|
||||
if (result == NULL)
|
||||
{
|
||||
write(1, "Erreur.", 7);
|
||||
}
|
||||
ft_putstr("Resultat : ");
|
||||
ft_putstr(result);
|
||||
write(1, "\n", 1);
|
||||
free(result);
|
||||
// Test 2 : 2a (42) > Hex to Vif
|
||||
ft_putstr("Test avec 42 (2a) | ");
|
||||
ft_putstr("Base From : Hexadecimal (Base 16), Base To : poneyvif (Base 8)");
|
||||
write(1, "\n", 1);
|
||||
result = ft_convert_base("2a", hex, vif);
|
||||
if (result == NULL)
|
||||
{
|
||||
write(1, "Erreur.", 7);
|
||||
}
|
||||
ft_putstr("Resultat : ");
|
||||
ft_putstr(result);
|
||||
write(1, "\n", 1);
|
||||
free(result);
|
||||
// Test 3 : 0 > Dec to Bin
|
||||
ft_putstr("Test avec 0 | ");
|
||||
ft_putstr("Base From : Decimal (Base 10), Base To : Binary (Base 2)");
|
||||
write(1, "\n", 1);
|
||||
result = ft_convert_base("0", dec, bin);
|
||||
if (result == NULL)
|
||||
{
|
||||
write(1, "Erreur.", 7);
|
||||
}
|
||||
ft_putstr("Resultat : ");
|
||||
ft_putstr(result);
|
||||
write(1, "\n", 1);
|
||||
free(result);
|
||||
// Test 4 : -2147483648 > Dec to Hex
|
||||
ft_putstr("Test avec -2147483648 | ");
|
||||
ft_putstr("Base From : Decimal (Base 10), Base To : Hexadecimal (Base 16)");
|
||||
write(1, "\n", 1);
|
||||
result = ft_convert_base("-2147483648", dec, hex);
|
||||
if (result == NULL)
|
||||
{
|
||||
write(1, "Erreur.", 7);
|
||||
}
|
||||
ft_putstr("Resultat : ");
|
||||
ft_putstr(result);
|
||||
write(1, "\n", 1);
|
||||
free(result);
|
||||
// Test 5 : Bordel Ultime > Binary to Dec
|
||||
ft_putstr("Test avec ---+--101010 | ");
|
||||
ft_putstr("Base From : Binary (Base 2), Base To : Decimal (Base 10)");
|
||||
write(1, "\n", 1);
|
||||
result = ft_convert_base(" ---+--101010", bin, dec);
|
||||
if (result == NULL)
|
||||
{
|
||||
write(1, "Erreur.", 7);
|
||||
}
|
||||
ft_putstr("Resultat : ");
|
||||
ft_putstr(result);
|
||||
write(1, "\n", 1);
|
||||
free(result);
|
||||
// Test 6 : NULL > Binary to Dec
|
||||
// ft_putstr("Test avec NULL | ");
|
||||
ft_putstr("Base From : Binary (Base 2), Base To : Decimal (Base 10)");
|
||||
write(1, "\n", 1);
|
||||
result = ft_convert_base(NULL, bin, dec);
|
||||
if (result == NULL)
|
||||
{
|
||||
write(1, "Erreur. NULL est mis comme variable", 35);
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putstr("Resultat : ");
|
||||
ft_putstr(result);
|
||||
write(1, "\n", 1);
|
||||
free(result);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_convert_base2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/17 14:22:20 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/17 18:16:30 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
write(1, &str[i], 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int ft_nbrlen(long nbr, int base_size)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if (nbr <= 0)
|
||||
{
|
||||
len++;
|
||||
if (nbr < 0)
|
||||
nbr = -nbr;
|
||||
}
|
||||
while (nbr > 0)
|
||||
{
|
||||
nbr /= base_size;
|
||||
len++;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
int check_base(char *base)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
if (!base[0] || !base[1])
|
||||
return (0);
|
||||
while (base[i])
|
||||
{
|
||||
if (base[i] == '+' || base[i] == '-'
|
||||
|| (base[i] >= 9 && base[i] <= 13)
|
||||
|| base[i] == 32)
|
||||
return (0);
|
||||
j = i + 1;
|
||||
while (base[j])
|
||||
{
|
||||
if (base[i] == base[j])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/18 10:29:59 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 19:27:27 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_sep(char c, char *charset)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (charset[i])
|
||||
{
|
||||
if (c == charset[i])
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_words(char *str, char *charset)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (ft_sep(str[i], charset) == 0
|
||||
&& (i == 0 || ft_sep(str[i - 1], charset) == 1))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
char *ft_get_word(char *str, char *charset)
|
||||
{
|
||||
char *word;
|
||||
int i;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
i = 0;
|
||||
while (str[len] && ft_sep(str[len], charset) == 0)
|
||||
len++;
|
||||
word = malloc(sizeof(char) * (len + 1));
|
||||
if (!word)
|
||||
return (NULL);
|
||||
while (i < len)
|
||||
{
|
||||
word[i] = str[i];
|
||||
i++;
|
||||
}
|
||||
word[i] = '\0';
|
||||
return (word);
|
||||
}
|
||||
|
||||
char **ft_split(char *str, char *charset)
|
||||
{
|
||||
char **res;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
res = malloc(sizeof(char *) * (ft_words(str, charset) + 1));
|
||||
if (!res)
|
||||
return (NULL);
|
||||
while (str[i])
|
||||
{
|
||||
while (str[i] && ft_sep(str[i], charset) == 1)
|
||||
i++;
|
||||
if (str[i])
|
||||
{
|
||||
res[j++] = ft_get_word(&str[i], charset);
|
||||
while (str[i] && ft_sep(str[i], charset) == 0)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
res[j] = 0;
|
||||
return (res);
|
||||
}
|
||||
/*
|
||||
int main(void)
|
||||
{
|
||||
char **res;
|
||||
int i;
|
||||
int j;
|
||||
res = ft_split("Ceci Est+Un+Test^Fait/Par&Lumi.", "+-^/&");
|
||||
i = 0;
|
||||
write(1, "Test avec : Ceci Est+Un-Test^Fait/Par&Lumi. : \n", 47);
|
||||
while (res[i])
|
||||
{
|
||||
j = 0;
|
||||
while (res[i][j])
|
||||
{
|
||||
write(1, &res[i][j], 1);
|
||||
j++;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}*/
|
||||
Submodule Memory Management/C-Pointers deleted from 09c4873fe3
@@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ft.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 16:50:01 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 17:31:41 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_ft(int *nbr)
|
||||
{
|
||||
*nbr = 42;
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int a;
|
||||
int *ptr1;
|
||||
|
||||
a = 0;
|
||||
ptr1 = &a;
|
||||
|
||||
write(1, "Avant : ", 8);
|
||||
ft_putnbr(a);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres : ", 8);
|
||||
ft_ft(ptr1);
|
||||
ft_putnbr(*ptr1);
|
||||
write(1, "\n", 1);
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,74 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_ft.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 16:52:51 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 17:29:03 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_ultimate_ft(int *********nbr)
|
||||
{
|
||||
*********nbr = 42;
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int a;
|
||||
int *ptr1;
|
||||
int **ptr2;
|
||||
int ***ptr3;
|
||||
int ****ptr4;
|
||||
int *****ptr5;
|
||||
int ******ptr6;
|
||||
int *******ptr7;
|
||||
int ********ptr8;
|
||||
int *********ptr9;
|
||||
|
||||
a = 0;
|
||||
ptr1 = &a;
|
||||
ptr2 = &ptr1;
|
||||
ptr3 = &ptr2;
|
||||
ptr4 = &ptr3;
|
||||
ptr5 = &ptr4;
|
||||
ptr6 = &ptr5;
|
||||
ptr7 = &ptr6;
|
||||
ptr8 = &ptr7;
|
||||
ptr9 = &ptr8;
|
||||
|
||||
write(1, "Avant : ", 8);
|
||||
ft_putnbr(a);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres : ", 8);
|
||||
ft_ultimate_ft(ptr9);
|
||||
ft_putnbr(*********ptr9);
|
||||
write(1, "\n", 1);
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 17:36:15 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 17:46:32 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_swap(int *a, int *b)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
|
||||
a = 3;
|
||||
b = 9;
|
||||
write(1, "Avant - a: ", 11);
|
||||
ft_putnbr(a);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Avant - b: ", 11);
|
||||
ft_putnbr(b);
|
||||
write(1, "\n", 1);
|
||||
ft_swap(&a, &b);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres - a: ", 11);
|
||||
ft_putnbr(a);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres - b: ", 11);
|
||||
ft_putnbr(b);
|
||||
write(1, "\n", 1);
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_div_mod.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 17:52:58 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 18:50:17 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_div_mod(int a, int b, int *div, int *mod)
|
||||
{
|
||||
*div = a / b;
|
||||
*mod = a % b;
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int res_div;
|
||||
int res_mod;
|
||||
|
||||
a = 42;
|
||||
b = 5;
|
||||
res_div = 0;
|
||||
res_mod = 0;
|
||||
ft_div_mod(a, b, &res_div, &res_mod);
|
||||
write(1, "Division de 42 par 5 :\n", 23);
|
||||
write(1, "Quotient : ", 11);
|
||||
ft_putnbr(res_div);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Reste : ", 8);
|
||||
ft_putnbr(res_mod);
|
||||
write(1, "\n", 1);
|
||||
}*/
|
||||
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_div_mod.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 18:53:55 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 19:05:23 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_ultimate_div_mod(int *a, int *b)
|
||||
{
|
||||
int temp_a;
|
||||
int temp_b;
|
||||
|
||||
temp_a = *a;
|
||||
temp_b = *b;
|
||||
*a = temp_a / temp_b;
|
||||
*b = temp_a % temp_b;
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
|
||||
a = 42;
|
||||
b = 5;
|
||||
write(1, "Avant : ", 8);
|
||||
ft_putnbr(a);
|
||||
write(1, " et ", 4);
|
||||
ft_putnbr(b);
|
||||
write(1, "\n", 1);
|
||||
ft_ultimate_div_mod(&a, &b);
|
||||
write(1, "Apres (Div) : ", 14);
|
||||
ft_putnbr(a);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres (Mod) : ", 14);
|
||||
ft_putnbr(b);
|
||||
write(1, "\n", 1);
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,76 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_rev_int_tab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 19:08:40 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 19:23:29 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_rev_int_tab(int *tab, int size)
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
int last;
|
||||
|
||||
i = 0;
|
||||
last = size - 1;
|
||||
while (i < size / 2)
|
||||
{
|
||||
temp = tab[i];
|
||||
tab[i] = tab[last];
|
||||
tab[last] = temp;
|
||||
i++;
|
||||
last--;
|
||||
}
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int tab[5] = {1, 2, 3, 4, 5};
|
||||
int size;
|
||||
|
||||
size = 5;
|
||||
write(1, "Avant : 1, 2, 3, 4, 5", 22);
|
||||
ft_rev_int_tab(tab, size);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres : ", 8);
|
||||
ft_putnbr(tab[0]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[1]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[2]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[3]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[4]);
|
||||
write(1, "\n", 1);
|
||||
return (0);
|
||||
}*/
|
||||
@@ -0,0 +1,87 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sort_int_tab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/09 19:24:29 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/09 19:34:56 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
void ft_sort_int_tab(int *tab, int size)
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
int changed;
|
||||
|
||||
changed = 1;
|
||||
while (changed)
|
||||
{
|
||||
changed = 0;
|
||||
i = 0;
|
||||
while (i < size -1)
|
||||
{
|
||||
if (tab[i] > tab[i + 1])
|
||||
{
|
||||
temp = tab[i];
|
||||
tab[i] = tab[i + 1];
|
||||
tab[i + 1] = temp;
|
||||
changed = 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int tab[] = {5, 1, 4, 2, 8, 9, 3, 7, 6};
|
||||
int size = 9;
|
||||
|
||||
ft_sort_int_tab(tab, size);
|
||||
ft_putnbr(tab[0]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[1]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[2]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[3]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[4]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[5]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[6]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[7]);
|
||||
write(1, ", ", 2);
|
||||
ft_putnbr(tab[8]);
|
||||
write(1, "\n ", 1);
|
||||
return (0);
|
||||
}*/
|
||||
Submodule Memory Management/C-Simple-Strings deleted from 5838a52b60
@@ -0,0 +1,55 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_alpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 09:59:54 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 13:14:35 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}*/
|
||||
|
||||
int ft_str_is_alpha(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_low;
|
||||
int is_up;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_up = (str[i] >= 'a' && str[i] <= 'z');
|
||||
is_low = (str[i] >= 'A' && str[i] <= 'Z');
|
||||
if (!(is_up || is_low))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = "LumiTest123";
|
||||
write(1, "Test avec LumiTest123 : ", 16);
|
||||
ft_putchar(ft_str_is_alpha(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 0 car y'as des chiffres", 32);
|
||||
write(1, "\n", 1);
|
||||
str = "LumiTest";
|
||||
write(1, "Test avec LumiTest : ", 21);
|
||||
ft_putchar(ft_str_is_alpha(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car y'as pas de chiffres", 35);
|
||||
}*/
|
||||
@@ -0,0 +1,55 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_alpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 09:59:54 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 13:14:35 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}*/
|
||||
|
||||
int ft_str_is_alpha(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_low;
|
||||
int is_up;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_up = (str[i] >= 'a' && str[i] <= 'z');
|
||||
is_low = (str[i] >= 'A' && str[i] <= 'Z');
|
||||
if (!(is_up || is_low))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = "LumiTest123";
|
||||
write(1, "Test avec LumiTest123 : ", 16);
|
||||
ft_putchar(ft_str_is_alpha(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 0 car y'as des chiffres", 32);
|
||||
write(1, "\n", 1);
|
||||
str = "LumiTest";
|
||||
write(1, "Test avec LumiTest : ", 21);
|
||||
ft_putchar(ft_str_is_alpha(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car y'as pas de chiffres", 35);
|
||||
}*/
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_numeric.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 09:59:54 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 11:31:44 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}*/
|
||||
|
||||
int ft_str_is_numeric(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_num;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_num = (str[i] >= '0' && str[i] <= '9');
|
||||
if (!(is_num))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = "123";
|
||||
write(1, "Test avec 123 : ", 16);
|
||||
ft_putchar(ft_str_is_numeric(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car y'as des chiffres", 32);
|
||||
write(1, "\n", 1);
|
||||
str = "LumiTest";
|
||||
write(1, "Test avec LumiTest : ", 21);
|
||||
ft_putchar(ft_str_is_numeric(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 0 car y'as pas de chiffres", 35);
|
||||
}*/
|
||||
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_non_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 17:05:58 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 17:17:53 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putstr_non_printable(char *str)
|
||||
{
|
||||
char *base;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
base = "0123456789abcdef";
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] >= 32 && str[i] <= 126)
|
||||
write(1, &str[i], 1);
|
||||
else
|
||||
{
|
||||
write(1, "\\", 1);
|
||||
write(1, &base[(unsigned char)str[i] / 16], 1);
|
||||
write(1, &base[(unsigned char)str[i] % 16], 1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ft_putstr_non_printable("Coucou\nLumi\n:3É");
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_lowercase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 09:59:54 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 13:15:46 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}*/
|
||||
|
||||
int ft_str_is_lowercase(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_low;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_low = (str[i] >= 'a' && str[i] <= 'z');
|
||||
if (!(is_low))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = "LumiTest123";
|
||||
write(1, "Test avec LumiTest123 : ", 24);
|
||||
ft_putchar(ft_str_is_lowercase(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 0 car y'as des majuscules", 34);
|
||||
write(1, "\n", 1);
|
||||
str = "lumitest";
|
||||
write(1, "Test avec lumitest : ", 21);
|
||||
ft_putchar(ft_str_is_lowercase(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car y'as pas de majuscules", 37);
|
||||
}*/
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_uppercase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 09:59:54 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 11:43:39 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}*/
|
||||
|
||||
int ft_str_is_uppercase(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_up;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_up = (str[i] >= 'A' && str[i] <= 'Z');
|
||||
if (!(is_up))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = "LumiTest123";
|
||||
write(1, "Test avec LumiTest123 : ", 24);
|
||||
ft_putchar(ft_str_is_uppercase(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 0 car y'as des minuscules", 34);
|
||||
write(1, "\n", 1);
|
||||
str = "LUMITEST";
|
||||
write(1, "Test avec LUMITEST : ", 21);
|
||||
ft_putchar(ft_str_is_uppercase(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car y'as pas de minuscules", 37);
|
||||
}*/
|
||||
@@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 12:02:31 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 13:16:41 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}*/
|
||||
|
||||
int ft_str_is_printable(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_print;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_print = (str[i] >= 32 && str[i] <= 126);
|
||||
if (!(is_print))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = "LumiTest123\n";
|
||||
write(1, "Test avec LumiTest123 (Backslash n) : ", 38);
|
||||
ft_putchar(ft_str_is_printable(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 0 car y'as un non-printable", 36);
|
||||
write(1, "\n", 1);
|
||||
str = "LumiTest123";
|
||||
write(1, "Test avec LumiTest123 : ", 24);
|
||||
ft_putchar(ft_str_is_printable(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car y'as pas de non-printable", 40);
|
||||
write(1, "\n", 1);
|
||||
str = "";
|
||||
write(1, "Test avec Rien (NULL) : ", 24);
|
||||
ft_putchar(ft_str_is_printable(str) + '0');
|
||||
write(1, "\n", 1);
|
||||
write(1, "Output = 1 car le sujet dis que NULL = 1", 40);
|
||||
}*/
|
||||
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strupcase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 12:39:09 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 13:13:29 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}*/
|
||||
|
||||
char *ft_strupcase(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_low;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_low = (str[i] >= 'a' && str[i] <= 'z');
|
||||
if (is_low)
|
||||
{
|
||||
str[i] = str[i] - 32;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char str[] = "LumiTest123";
|
||||
|
||||
write(1, "Test avec LumiTest123 : ", 24);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Avant : ", 8);
|
||||
ft_putstr(str);
|
||||
ft_strupcase(str);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres : ", 8);
|
||||
ft_putstr(str);
|
||||
}*/
|
||||
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlowcase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 12:39:09 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 18:44:55 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}*/
|
||||
|
||||
char *ft_strlowcase(char *str)
|
||||
{
|
||||
int i;
|
||||
int is_up;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0' )
|
||||
{
|
||||
is_up = (str[i] >= 'A' && str[i] <= 'Z');
|
||||
if (is_up)
|
||||
{
|
||||
str[i] = str[i] + 32;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char str[] = "LumiTest123";
|
||||
|
||||
write(1, "Test avec LumiTest123 : ", 24);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Avant : ", 8);
|
||||
ft_putstr(str);
|
||||
ft_strlowcase(str);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres : ", 8);
|
||||
ft_putstr(str);
|
||||
}*/
|
||||
@@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcapitalize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 14:30:14 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 16:07:45 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}*/
|
||||
|
||||
char *ft_strcapitalize(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] >= 'A' && str[i] <= 'Z')
|
||||
str[i] += 32;
|
||||
if ((str[i] >= 'a' && str[i] <= 'z'))
|
||||
{
|
||||
if (i == 0 || !((str[i - 1] >= 'a' && str[i - 1] <= 'z')
|
||||
|| (str[i - 1] >= 'A' && str[i - 1] <= 'Z')
|
||||
|| (str[i - 1] >= '0' && str[i - 1] <= '9')))
|
||||
{
|
||||
str[i] -= 32;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char str[] = "salut, ceci-est un+test";
|
||||
|
||||
write(1, "Avant : ", 8);
|
||||
ft_putstr(str);
|
||||
ft_strcapitalize(str);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Apres : ", 8);
|
||||
ft_putstr(str);
|
||||
write(1, "\n", 1);
|
||||
}*/
|
||||
@@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 16:35:32 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 16:57:13 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*void ft_putnbr(int nb)
|
||||
{
|
||||
char value;
|
||||
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
return ;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
}
|
||||
value = nb % 10 + '0';
|
||||
write(1, &value, 1);
|
||||
}*/
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
int len;
|
||||
|
||||
write(1, "Test avec TestLumi : ", 21);
|
||||
len = ft_strlen("TestLumi");
|
||||
ft_putnbr(len);
|
||||
write(1, "\n", 1);
|
||||
write(1, "Test avec Je suis un code C : ", 30);
|
||||
len = ft_strlen("Je suis un code C");
|
||||
ft_putnbr(len);
|
||||
write(1, "\n", 1);
|
||||
}*/
|
||||
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/10 14:04:52 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/10 14:21:43 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
ft_putchar(str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/*int main(void)
|
||||
{
|
||||
char str[] = "Test_Lumi";
|
||||
|
||||
write(1, "Test avec Test_Lumi : ", 24);
|
||||
ft_putstr(str);
|
||||
}*/
|
||||
Submodule Memory Management/C-System-Interface deleted from 4b8aa8530c
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_program_name.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/19 15:36:50 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 18:05:56 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
(void)argc;
|
||||
i = 0;
|
||||
while (argv[0][i] != '\0')
|
||||
i++;
|
||||
write(1, argv[0], i);
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/19 16:03:11 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 18:05:40 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
(void)argc;
|
||||
i = 1;
|
||||
while (i < argc)
|
||||
{
|
||||
len = 0;
|
||||
while (argv[i][len] != '\0')
|
||||
len++;
|
||||
write(1, argv[i], len);
|
||||
write(1, "\n", 1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_rev_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/19 16:09:13 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 18:05:23 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
(void)argc;
|
||||
i = argc - 1;
|
||||
while (i > 0)
|
||||
{
|
||||
len = 0;
|
||||
while (argv[i][len] != '\0')
|
||||
len++;
|
||||
write(1, argv[i], len);
|
||||
write(1, "\n", 1);
|
||||
i--;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sort_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/19 16:47:37 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/19 18:09:21 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] != '\0' && s1[i] == s2[i])
|
||||
i++;
|
||||
return (s1[i] - s2[i]);
|
||||
}
|
||||
|
||||
void ft_display(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
i = 1;
|
||||
while (i < argc)
|
||||
{
|
||||
len = 0;
|
||||
while (argv[i][len])
|
||||
len++;
|
||||
write(1, argv[i], len);
|
||||
write(1, "\n", 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *temp;
|
||||
|
||||
if (argc < 2)
|
||||
return (0);
|
||||
i = 1;
|
||||
while (i < argc - 1)
|
||||
{
|
||||
j = i + 1;
|
||||
while (j < argc)
|
||||
{
|
||||
if (ft_strcmp(argv[i], argv[j]) > 0)
|
||||
{
|
||||
temp = argv[i];
|
||||
argv[i] = argv[j];
|
||||
argv[j] = temp;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ft_display(argc, argv);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user