Example #1
0
static char	*ft_ltoa_real(long int n, char *dst)
{
	long int			rlt;
	int					neg;
	int					i;

	i = 0;
	rlt = 0;
	neg = n;
	if (n == -1)
	{
		dst[i] = '-';
		dst[i + 1] = '1';
		dst[i + 2] = '\0';
		return (dst);
	}
	if (n < 0)
	{
		n = -n;
		n--;
	}
	dst = ft_ltoa_res(n, rlt, dst, neg);
	dst[20] = '\0';
	dst = ft_reverse(dst);
	return (dst);
}
Example #2
0
static void	print_addr(void *addr, int end_line)
{
	char	buffer[128];
	char	hex[17];
	int		len;
	int		i;
	size_t	laddr;

	i = 0;
	len = 8;
	hex[16] = 0;
	laddr = (size_t)addr;
	ft_strcpy(hex, "0123456789ABCDEF");
	ft_bzero(buffer, 128);
	while (laddr)
	{
		buffer[i] = hex[laddr % 16];
		laddr /= 16;
		i++;
	}
	ft_putstr("0x");
	ft_putstr(ft_reverse(buffer));
	if (end_line)
		ft_putchar('\n');
}
Example #3
0
char		*ft_itoa(int n)
{
	char	*s;
	int		i;
	int		tmp;
	int		j;

	i = 0;
	j = 0;
	if ((s = ft_test_spec(n)))
		return (s);
	if ((s = (char *)malloc(sizeof(char) * ft_intlen(n))) == NULL)
		return (0);
	if (n < 0)
	{
		j++;
		n = n * -1;
	}
	while (n != 0)
	{
		tmp = n % 10;
		s[i++] = tmp + '0';
		n = n / 10;
	}
	s[i] = '\0';
	return (ft_reverse(s, j));
}
Example #4
0
static char	*ft_itoa_it(int n, char *str)
{
	int		sign;
	int		i;

	sign = (n < 0) ? 1 : 0;
	i = 0;
	if (n == 0)
	{
		str[i++] = '0';
	}
	else if (n < 0)
	{
		str[i++] = '-';
		n = -n;
	}
	while (n > 0)
	{
		str[i++] = (n % 10) + '0';
		n /= 10;
	}
	str[i] = '\0';
	ft_reverse(str + sign, i - sign);
	return (str);
}
Example #5
0
File: ft_itoa.c Project: rioru/42
char			*ft_itoa_un(unsigned int n, unsigned int base, int casse)
{
    char		*str;
    char		*ptr;

    if (!(str = (char *)malloc(sizeof(char) * 12)))
        return (NULL);
    ptr = str;
    while (n >= base)
    {
        if (n % base < 10)
            *ptr = n % base + '0';
        else
            *ptr = n % base - 10 + casse;
        ptr++;
        n = n / base;
    }
    if (n < 10)
        *ptr = n + '0';
    else
        *ptr = n - 10 + casse;
    ptr++;
    *ptr = '\0';
    ft_reverse(str);
    return (str);
}
Example #6
0
File: ft_itoa.c Project: rioru/42
char			*ft_itoa(int n)
{
    char		*str;
    char		*ptr;

    if (!(str = (char *)malloc(sizeof(char) * 12)))
        return (NULL);
    ptr = str;
    if (n <= 0)
    {
        if (n == -2147483648)
            return (ft_strcpy(ptr, "2147483648"));
        if (n == 0)
            return (ft_strcpy(ptr, "0"));
        n *= -1;
    }
    while (n >= 1)
    {
        *ptr++ = n % 10 + '0';
        n = n / 10;
    }
    *ptr = '\0';
    ft_reverse(str);
    return (str);
}
Example #7
0
static char	*finish_ret(int sign, char *ret, int i)
{
	if (sign == -1)
		ret[i++] = '-';
	ret[i] = '\0';
	ret = ft_reverse(ret);
	return (ret);
}
Example #8
0
char			*ft_itoa_base(unsigned long long n, int base)
{
	char	*str;
	int		i;

	i = 0;
	if (!(str = (char *)malloc(sizeof(char) * 256 + 1)))
		return (NULL);
	else if (n == 0)
		return (if_zero(str));
	else
	{
		str = fill(n, str, base);
		ft_reverse(str);
	}
	return (str);
}
Example #9
0
char			*ft_itoa(int n)
{
	char	*str;
	int		i;

	i = 0;
	if (n < 0)
		str = (char*)malloc(nb_of_nb(n) + 2);
	else
		str = (char*)malloc(nb_of_nb(n) + 1);
	if (str == NULL)
		return (NULL);
	if (n == -2147483648)
		return (ft_strcpy(str, "-2147483648"));
	else if (n == 0)
		return (if_zero(str));
	else
	{
		str = fill(n, str);
		ft_reverse(str);
	}
	return (str);
}