Ejemplo n.º 1
0
void	ft_itoa(char *tab, int i, int result)
{
	int j;
	int tmp;
	int	abs;

	j = 1;
	abs = 0;
	tmp = result;
	i++;
	if (result)
	{
		if (result < 0)
		{
			result *= -1;
			tab[i++] = '-';
		}
		while (tmp != 0)
		{
			tmp /= 10;
			j *= 10;
		}
		j /= 10;
		ft_itoa2(j, result, i, tab);
	}
	else
		tab[i] = '0';
}
Ejemplo n.º 2
0
Archivo: ft_itoa.c Proyecto: TPelago/42
char		*ft_itoa(int number)
{
	int		number2;
	int		negative;
	size_t	size_str;
	char	*str_number;

	size_str = 0;
	negative = 0;
	if (number == 0 || number == -2147483648)
		return (ft_exception(number));
	if (number < 0 && ++negative)
		number = -number;
	number2 = number;
	while (number)
	{
		number = number / 10;
		size_str++;
	}
	str_number = malloc(sizeof(char) * (size_str + 1));
	if (!str_number)
		return (0);
	ft_itoa2(number2, &str_number, negative, 0);
	return (ft_strrev(str_number));
}
Ejemplo n.º 3
0
char			*ft_itoa(int nb)
{
    char	*result;

    if (nb == 0)
    {
        result = malloc(2);
        result = "0";
        return (result);
    }
    else if (nb == -2147483648)
    {
        result = malloc(12);
        result = "-2147483648\0";
        return (result);
    }
    else if (nb == 2147483647)
    {
        result = malloc(12);
        result = "2147483647\0";
        return (result);
    }
    else
        result = ft_itoa2(nb);
    return (result);
}