0
0
This commit is contained in:
Guy Baconniere
2021-08-16 16:51:24 +02:00
parent 0909750997
commit ef1c6b5e75
16 changed files with 332 additions and 10 deletions

View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/16 13:53:46 by gbaconni #+# #+# */
/* Updated: 2021/08/16 15:05:08 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
static int ft_strlen(char *str)
{
int size;
size = 0;
while (str[++size] != '\0')
continue ;
return (size);
}
static int ft_nbase(char c, char *base)
{
int n;
n = 0;
while (base[n] != '\0' && base[n] != c)
n++;
return (n);
}
int ft_atoi_base(char *str, char *base)
{
int nb;
int s;
int i;
int size;
size = ft_strlen(base);
nb = 0;
s = 1;
i = 0;
while (str[i] != '\0' && (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')))
i++;
while (str[i] != '\0')
{
if (str[i] == '+')
s += 0;
else if (str[i] == '-')
s *= -1;
else
nb = nb * size + ft_nbase(str[i], base);
i++;
}
return (nb * s);
}