1
0

first commit

This commit is contained in:
KeyZox
2023-08-06 20:12:38 +02:00
parent 1fe062c970
commit eb6b113e51
125 changed files with 2987 additions and 0 deletions

View 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);
}

View 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++;
}
}

View 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
View 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);
}

View 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);
}
}