48 lines
1.3 KiB
C
48 lines
1.3 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_tabnbr.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2022/07/31 20:57:07 by cchauvet #+# #+# */
|
||
|
/* Updated: 2022/07/31 20:57:09 by cchauvet ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "rush02.h"
|
||
|
|
||
|
int ft_lenght(unsigned int nb)
|
||
|
{
|
||
|
int a;
|
||
|
|
||
|
a = 1;
|
||
|
while (nb / 10 != 0)
|
||
|
{
|
||
|
nb = nb / 10;
|
||
|
a = a * 10;
|
||
|
}
|
||
|
return (a);
|
||
|
}
|
||
|
|
||
|
char *ft_tabnbr(unsigned int nb)
|
||
|
{
|
||
|
unsigned int nbr;
|
||
|
int a;
|
||
|
char *tab;
|
||
|
int i;
|
||
|
|
||
|
i = -1;
|
||
|
nbr = nb;
|
||
|
a = ft_lenght(nbr);
|
||
|
tab = malloc(sizeof(*tab) * a);
|
||
|
while (a != 0)
|
||
|
{
|
||
|
tab[++i] = nbr / a + 48;
|
||
|
nbr = nbr % a;
|
||
|
a = a / 10;
|
||
|
}
|
||
|
tab[++i] = '\0';
|
||
|
return (tab);
|
||
|
}
|