first commit
This commit is contained in:
21
ended/C04/ex00/ft_strlen.c
Normal file
21
ended/C04/ex00/ft_strlen.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/25 10:23:43 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/25 10:23:45 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
24
ended/C04/ex01/ft_putstr.c
Normal file
24
ended/C04/ex01/ft_putstr.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/25 12:11:23 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/25 12:11:25 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
write(1, &str[i], 1);
|
||||
i++;
|
||||
}
|
||||
}
|
36
ended/C04/ex02/ft_putnbr.c
Normal file
36
ended/C04/ex02/ft_putnbr.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/25 13:03:53 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/25 13:03:55 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
long nb_long;
|
||||
int nb_temp;
|
||||
int div;
|
||||
|
||||
nb_long = nb;
|
||||
div = 1;
|
||||
if (nb_long < 0)
|
||||
{
|
||||
write(1, "-", 1);
|
||||
nb_long *= -1;
|
||||
}
|
||||
while (nb_long / 10 >= div)
|
||||
div *= 10;
|
||||
while (div >= 1)
|
||||
{
|
||||
nb_temp = (nb_long / div) + 48;
|
||||
write(1, &nb_temp, 1);
|
||||
nb_long = nb_long % div;
|
||||
div = div / 10;
|
||||
}
|
||||
}
|
37
ended/C04/ex03/ft_atoi.c
Normal file
37
ended/C04/ex03/ft_atoi.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/25 13:48:15 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/25 13:48:19 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int i;
|
||||
int result;
|
||||
int neg;
|
||||
|
||||
i = 0;
|
||||
neg = 1;
|
||||
result = 0;
|
||||
while (str[i] == ' ' || str[i] == '\t' || str[i] == '\r'
|
||||
|| str[i] == '\n' || str[i] == '\v' || str[i] == '\f')
|
||||
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++;
|
||||
}
|
||||
return (result * neg);
|
||||
}
|
62
ended/C04/ex04/ft_putnbr_base.c
Normal file
62
ended/C04/ex04/ft_putnbr_base.c
Normal file
@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/26 13:30:23 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/26 13:30:27 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include <unistd.h>
|
||||
|
||||
int check_base(char *base)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (base[0] == '\0' && base[1] == '\0')
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
while (base[i])
|
||||
{
|
||||
if (base[i] < 26 || base[i] > 126)
|
||||
return (0);
|
||||
if (base[i] == '+' || base[i] == '-')
|
||||
return (0);
|
||||
if (base[i] == base[i + 1])
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void ft_putnbr_base(int nbr, char *base)
|
||||
{
|
||||
int base_count;
|
||||
int i;
|
||||
int final[255];
|
||||
|
||||
i = 0;
|
||||
base_count = 0;
|
||||
if (check_base(base))
|
||||
{
|
||||
if (nbr < 0)
|
||||
{
|
||||
nbr = -nbr;
|
||||
write(1, "-", 1);
|
||||
}
|
||||
while (base[base_count])
|
||||
base_count++;
|
||||
while (nbr)
|
||||
{
|
||||
final[i] = nbr % base_count;
|
||||
nbr = nbr / base_count;
|
||||
i++;
|
||||
}
|
||||
while (--i >= 0)
|
||||
write(1, &base[final[i]], 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user