This commit is contained in:
lclerel- lclerel-
2026-03-12 17:06:05 +01:00
commit 9c35f32ffd
4 changed files with 296 additions and 0 deletions

66
ex0/ft_foreach.c Normal file
View 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);
}
}*/