char *ft_convert_base(char *nbr, char *base_from, char *base_to) { int nb; int j; char *res; int i; j = 1; i = 0; nb = ft_atoi_base(nbr, base_from); ft_len_nb(&j, &i, base_to, nb); res = (char*)malloc(sizeof(char) * (i + ((nb < 0) ? 1 : 0))); i = (nb < 0) ? 1 : 0; res[0] = '-'; j = (nb < 0) ? j * ft_strlen(base_to) : j; nb = (nb < 0) ? -nb : nb; while (j > 0) { res[i] = base_to[(nb / j) % ft_strlen(base_to)]; j /= ft_strlen(base_to); i++; } res[i] = '\0'; return (res); }
char *ft_itoa(int n) { char *str; int len; long m; len = ft_len_nb(n); m = n; str = (char *)malloc(sizeof(char) * (len + 1)); str[len--] = 0; if (m < 0) str[0] = '-'; if (m == 0) { str[0] = '0'; return (str); } if (m < 0) m = m * -1; while (m != 0) { str[len] = (m % 10) + '0'; m = m / 10; len--; } len++; return (str); }