#include <stdlib.h>

static int	count_chiffres(long n)
{
	int	len;

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

char	*ft_itoa(int n)
{
	long	nb;
	int		len;
	char	*str;

	nb = (long)n;
	len = count_chiffres(nb);
	str = malloc(sizeof(char) * (len + 1));
	if (!str)
		return (NULL);
	str[len] = '\0';
	if (nb == 0)
		str[0] = '0';
	if (nb < 0)
	{
		str[0] = '-';
		nb = -nb;
	}
	while (nb > 0)
	{
		str[--len] = '0' + (nb % 10);
		nb /= 10;
	}
	return (str);
}

#include <stdio.h>

int 	main(void)
{
	int	m;
	m = 42258763;
	printf("%s\n",ft_itoa(m));
	return (0);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: