1
0

first commit

This commit is contained in:
Adam Joly
2023-08-03 23:16:27 +02:00
parent 7f3254f1c5
commit a80c4d61d7
133 changed files with 4293 additions and 0 deletions

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 08:44:17 by adjoly #+# #+# */
/* Updated: 2023/07/19 08:57:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 08:58:22 by adjoly #+# #+# */
/* Updated: 2023/07/19 09:02:13 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 13:51:06 by adjoly #+# #+# */
/* Updated: 2023/07/25 12:57:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putnbr(int nb)
{
unsigned int nbr;
if (nb < 0)
{
write(1, "-", 1);
nbr = -nb;
}
else
nbr = nb;
if (nbr < 10)
write(1, &(char){nbr + 48}, 1);
else
{
ft_putnbr(nbr / 10);
write(1, &(char){nbr % 10 + 48}, 1);
}
}

37
finish/C04/ex03/ft_atoi.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 09:27:06 by adjoly #+# #+# */
/* Updated: 2023/07/26 09:56:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int i;
int neg;
int result;
i = 0;
neg = 1;
result = 0;
while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13))
i++;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
neg *= -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
result = (result * 10) + str[i] - 48;
i++;
}
result *= neg;
return (result);
}

View File

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 14:25:29 by adjoly #+# #+# */
/* Updated: 2023/07/25 09:20:02 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int ft_checkbase(char *base)
{
int i;
int j;
i = 0;
if (ft_strlen(base) <= 1)
return (1);
while (base[i])
{
if (base[i] == '-' || base[i] == '+')
return (1);
j = i + 1;
while (base[j])
{
if (base[i] == base[j])
return (1);
j++;
}
i++;
}
return (0);
}
void ft_putnbr_base(int nbr, char *base)
{
unsigned int len;
unsigned int y;
if (ft_checkbase(base) == 1)
return ;
len = ft_strlen(base);
if (nbr < 0)
{
write(1, "-", 1);
y = -nbr;
}
else
y = nbr;
if (y < len)
write(1, &(char){base[y]}, 1);
else
{
ft_putnbr_base(y / len, base);
write(1, &(char){base[y % len]}, 1);
}
}