#include <stdlib.h>
int check_base(char *base); // proto de la function checkbase
int ft_strlen(char *str) // permet d avoir la longueur de la chaine
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int wordc(long nbr, char *base_to) //
{
int i;
i = 0;
if (nbr < 0)
i++;
while (nbr != 0)
{
nbr /= ft_strlen(base_to);
i++;
}
return (i);
}
void fill_itoa(int *i, char *itoa, long nbr, char *base_to)
{
if (nbr < 0)
{
itoa[(*i)] = '-';
(*i)++;
nbr *= -1;
}
if (nbr >= ft_strlen(base_to))
{
fill_itoa(i, itoa, nbr / ft_strlen(base_to), base_to);
fill_itoa(i, itoa, nbr % ft_strlen(base_to), base_to);
}
else
{
itoa[(*i)] = base_to[nbr];
(*i)++;
}
}
char *ft_itoa_base(long nbr, char *base_to)
{
int i;
char *itoa;
i = 0;
if (check_base(base_to) == 0)
return (NULL);
itoa = malloc((wordc(nbr, base_to) + 1) * sizeof(char));
fill_itoa(&i, itoa, nbr, base_to);
itoa[i] = '\0';
return (itoa);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: