Exos
This commit is contained in:
66
ex0/ft_foreach.c
Normal file
66
ex0/ft_foreach.c
Normal file
@@ -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/12 11:26:41 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);
|
||||
}
|
||||
}*/
|
||||
80
ex1/ft_map.c
Normal file
80
ex1/ft_map.c
Normal file
@@ -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/12 11:28:20 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);
|
||||
}
|
||||
}*/
|
||||
58
ex2/ft_any.c
Normal file
58
ex2/ft_any.c
Normal file
@@ -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/12 11:50:58 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);
|
||||
}*/
|
||||
92
ex3/ft_count_if.c
Normal file
92
ex3/ft_count_if.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_count_if.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/12 11:54:32 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/12 14:00:32 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;
|
||||
while (tab[i] != NULL)
|
||||
{
|
||||
if (f(tab[i]) < length)
|
||||
{
|
||||
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);
|
||||
}*/
|
||||
Reference in New Issue
Block a user