/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_u_itoa.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: pbonilla <eirodeis.lepnj@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/11/24 21:27:16 by pbonilla          #+#    #+#             */
/*   Updated: 2021/03/19 18:16:49 by pbonilla         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"

int						number_u_len(unsigned long long n)
{
	int					size;

	if (n == 0)
		return (1);
	size = 0;
	n = -n;
	++size;
	while (n != 0)
	{
		n /= 10;
		++size;
	}
	return (size);
}

char					*ft_u_itoa(unsigned long long n)
{
	unsigned long long	long_n;
	char				*number;
	int					size;

	long_n = n;
	size = number_u_len(n);
	if (!(number = malloc(sizeof(char) * (size + 1))))
		return (NULL);
	number[size] = 0;
	--size;
	while (size >= 0)
	{
		number[size] = '0' + (long_n % 10);
		--size;
		long_n /= 10;
	}
	return (number);
}