You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
35 lines
1.2 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_itox.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/12/21 09:51:26 by narnaud #+# #+# */
|
|
/* Updated: 2021/12/21 09:56:39 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_itox(unsigned long int n, const char *base)
|
|
{
|
|
char *ret;
|
|
size_t i;
|
|
unsigned int neg;
|
|
size_t size;
|
|
|
|
size = ft_longbaselen(n, 16);
|
|
if (n == 0)
|
|
return (ft_strdup("0"));
|
|
i = 0;
|
|
neg = 0;
|
|
ret = ft_calloc(size + 1, sizeof(char));
|
|
while (n)
|
|
{
|
|
ret[i++] = base[n % 16];
|
|
n = n / 16;
|
|
}
|
|
ft_strrev(&ret, neg);
|
|
return (ret);
|
|
}
|
|
|