fractol/libft/src/ft_utoa.c
2023-03-01 04:36:42 +01:00

36 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_utoa.c :+: :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/12 23:20:24 by djonker #+# #+# */
/* Updated: 2023/02/07 00:41:45 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_utoa(unsigned long long n)
{
char *r;
int l;
l = ft_intlen(n) - 1;
r = ft_calloc(l + 2, 1);
if (r == NULL)
return (NULL);
while (n > 9 || n < 0)
{
if (n >= 10)
{
r[l] = n % 10 + '0';
l--;
n = (n / 10);
}
}
r[l] = n + '0';
return (r);
}