This commit is contained in:
Camille Chauvet
2023-05-17 16:45:25 +00:00
commit 29ed24d567
619 changed files with 16119 additions and 0 deletions

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 15:05:40 by cchauvet #+# #+# */
/* Updated: 2022/07/25 09:59:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}

View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 15:04:52 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
while (*str != 0)
write(1, str++, 1);
}

View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 14:48:52 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:23 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nbr)
{
if (nbr == -2147483648)
{
ft_putnbr(-2);
ft_putnbr(147483648);
}
else if (nbr < 0)
{
ft_putchar('-');
ft_putnbr(-nbr);
}
else if (nbr > 9)
{
ft_putnbr(nbr / 10);
ft_putnbr(nbr % 10);
}
else
{
ft_putchar(nbr + 48);
}
}

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 10:08:23 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:39 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int i;
int sign;
int nbr;
i = 0;
sign = 1;
nbr = 0;
while (str[i] == ' ')
i++;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
sign = sign * -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nbr = (nbr * 10 + (str[i] - '0'));
i++;
}
return (nbr * sign);
}

BIN
Correction/c04corec/ex04/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 13:52:59 by cchauvet #+# #+# */
/* Updated: 2022/07/25 16:14:09 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_baser(char *str)
{
int i;
int j;
int count;
i = -1;
while (str[++i] != 0)
{
count = 0;
j = 0;
while (str[j] != 0)
{
if (str[i] == str[j])
count++;
j++;
}
if (count > 1)
return (0);
if (str[i] == '+')
return (0);
if (str[i] == '-')
return (0);
}
if (i == 1)
return (0);
return (i);
}
void ft_put(char c)
{
write(1, &c, 1);
}
void ft_putnbr_base(int nbr, char *base)
{
int base_size;
base_size = ft_baser(base);
if (base_size == 0)
return ;
if (nbr == -2147483648)
{
ft_putnbr_base(-2, base);
ft_putnbr_base(147483648, base);
}
else if (nbr < 0)
{
ft_put('-');
ft_putnbr_base(-nbr, base);
}
else if (nbr > base_size - 1)
{
ft_putnbr_base(nbr / base_size, base);
ft_putnbr_base(nbr % base_size, base);
}
else
ft_put(base[nbr]);
}
int main(void)
{
ft_putnbr_base(56, "0123456789abcdef");
}

View File

@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 14:48:20 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:01:52 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_baser(char *str)
{
int i;
int j;
int count;
i = -1;
while (str[++i] != 0)
{
count = 0;
j = 0;
while (str[j] != 0)
if (str[i] == str[j++])
count++;
if (count > 1 || str[i] == '+' || str[i] == '-')
return (0);
}
if (i == 1)
return (0);
return (i);
}
int ft_find(char *str, char to_find)
{
int i;
i = 0;
while (str[i] != 0)
{
if (str[i] == to_find)
return (i);
i++;
}
return (-1);
}
int ft_atoi_base(char *str, char *base)
{
int base_size;
int sign;
int nbr;
int i;
nbr = 0;
sign = 1;
base_size = ft_baser(base);
i = 0;
if (base == 0)
return (0);
while (str[i] != ' ')
i++;
while (str[i] == '+' || str[i] == '-')
if (str[i++] == '-')
sign = sign * -1;
while (ft_find(base, str[i]) != -1)
{
nbr = nbr * base_size + ft_find(base, str[i]);
str++;
}
return (nbr * sign);
}