philosopher/utils/ft_itoa.c
Etienne Rey-bethbeder 3a9d944f74 Help
2023-03-25 04:07:47 +01:00

39 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:12:52 by erey-bet #+# #+# */
/* Updated: 2023/03/24 16:35:39 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
char *ft_itoa(long long n)
{
char *str;
long long q;
long long i;
q = 10;
i = 0;
while (n / q > 0)
{
q = q * 10;
i++;
}
str = malloc(sizeof(char) * i + 1);
if (!str)
return (NULL);
i = 0;
while (q > 1)
{;
str[i++] = (n / q % 10) + 48;
q = q / 10;
}
return (str);
}