libft/src/ft_ddtoi.c
2023-04-15 06:46:13 +02:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_ddtoi.c :+: :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2021/01/31 01:24:28 by djonker #+# #+# */
/* Updated: 2023/02/07 00:38:44 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_ddtoi(char *str)
{
int r;
int p;
r = 0;
p = ft_strlen(str) - 1;
while (p >= 0)
{
if (*str >= '0' && *str <= '9')
r = r + (*str - '0') * ft_power(12, p);
else if ((*str >= 'a' && *str <= 'b') || (*str >= 'A' && *str <= 'B'))
r = r + ft_dtoh(*str) * ft_power(12, p);
else
return (-0);
str++;
p--;
}
return (r);
}