コード例 #1
0
int	ft_atoi_base(char *str, char *base)
{
	int i;
	int s;
	int nbr;
	int nbr_final;
	int size_base;

	i = 0;
	s = 1;
	nbr_final = 0;
	size_base = 0;
	if (ft_check_str(str, base) && ft_check_base(base))
	{
		while (((str[i] >= 9) && (str[i] <= 13)) || str[i] == 32)
			i++;
		if (str[i] == '-')
		{
			s = -1;
			i++;
		}
		else if (str[i] == '+')
			i++;
		nbr = get_nbr(str, base, i);
		while (base[size_base])
			size_base++;
		i = 0;
		nbr *= 10;
		while ((nbr /= 10) > 0)
			nbr_final += (nbr % 10) * ft_power(size_base, i++);
	}
	return (nbr_final * s);
}
コード例 #2
0
int	main (void)
{
	char str[] = "-eqweq";
	char base[] = "qwerty";

	printf("%d", ft_check_str(str, base));
	printf("\n");
	printf("%d", ft_check_base(base));
	printf("\n");
	printf("%d\n", ft_atoi_base(str, base));
	return (0);
}
コード例 #3
0
ファイル: ft_atoi_base.c プロジェクト: 42Bfleury/Piscine42
int			ft_atoi_base(char *str, char *base)
{
	int		b;
	int		result;
	int		negative;

	result = 0;
	while (*str == '\v' || *str == '\t' || *str == '\f'
	|| *str == '\r' || *str == '\n' || *str == ' ')
		str++;
	if ((negative = 0) || *str == '-' || *str == '+')
		negative = ((*str++ == '-') ? 1 : 0);
	if ((b = ft_check_base(base)) && ft_check_str(str, base))
		while (*str++)
			result = ((b == 2 && !result) ? ft_get_rank(*(str - 1), base)
			: ((result * b) + ft_get_rank(*(str - 1), base)));
	return ((negative) ? -result : result);
}