init
This commit is contained in:
21
C/c04v1/ex00/ft_strlen.c
Normal file
21
C/c04v1/ex00/ft_strlen.c
Normal 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);
|
||||
}
|
19
C/c04v1/ex01/ft_putstr.c
Normal file
19
C/c04v1/ex01/ft_putstr.c
Normal 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);
|
||||
}
|
41
C/c04v1/ex02/ft_putnbr.c
Normal file
41
C/c04v1/ex02/ft_putnbr.c
Normal 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);
|
||||
}
|
||||
}
|
36
C/c04v1/ex03/ft_atoi.c
Normal file
36
C/c04v1/ex03/ft_atoi.c
Normal 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);
|
||||
}
|
73
C/c04v1/ex04/ft_putnbr_base.c
Normal file
73
C/c04v1/ex04/ft_putnbr_base.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 13:52:59 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 10:01:01 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]);
|
||||
}
|
73
C/c04v1/ex05/ft_atoi_base.c
Normal file
73
C/c04v1/ex05/ft_atoi_base.c
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user