/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* decompose.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet '0') { if ((ft_strlen(nbr) - *c) % 3 == 0) { tab[(*i)++] = ctoa(nbr[*c], 2); tab[*i] = malloc(sizeof(**tab) * 20); tab[(*i)++] = "100"; } else if ((ft_strlen(nbr) - *c) % 3 == 2) { if (nbr[*c] == '1') { if (nbr[*c + 1] > '0') { tab[(*i)++] = cat(ctoa(nbr[*c], 3), ctoa(nbr[*c + 1], 2)); *c = *c + 1; } } else tab[(*i)++] = cat(ctoa(nbr[*c], 3), "0"); } else tab[(*i)++] = ctoa(nbr[*c], 2); } } void ft_last_value(char **str, int *i) { str[*i] = malloc(sizeof(**str)); str[*i] = ""; } char **ft_decompose(char *nbr) { unsigned int packets; int *i; int *c; char **tab; i = malloc(sizeof(*i)); *i = 0; c = malloc(sizeof(*i)); *c = 0; tab = malloc(sizeof(*tab) * 20); packets = ft_strlen(nbr) / 3 + ((ft_strlen(nbr) % 3) != 0); while (nbr[*c] != '\0') { ft_decompose_by_char(tab, i, c, nbr); if (packets > 1) { if ((ft_strlen(nbr) - *c) % 3 == 1) { tab[*i] = malloc(sizeof(**tab) * 20); tab[*i] = ft_power_of_ten(ft_strlen(nbr) - *c); } } *c += 1; } ft_last_value(tab, i); return (tab); }