/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet 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_whitespaces(char *str) { char *space; int j; int i; space = "\n\r\v\t\n "; i = 0; j = 0; while (space[i] != 0) { while (str[j] == space[i]) { if (str[j] == 0) return (j); i = 0; j++; } i++; } return (j); } 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); if (base == 0) return (0); i = ft_whitespaces(str); 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); }