/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_cut_nbr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lvincent +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/31 19:07:48 by julemart #+# #+# */ /* Updated: 2022/07/31 23:35:38 by lvincent ### ########.fr */ /* */ /* ************************************************************************** */ #include "rush02.h" char **i_is_1(char **tab, char *nbr) { char *temp; temp = malloc(2); if (nbr[1] == '1') { temp[0] = nbr[1]; temp[1] = nbr[2]; tab = add_tab_str(tab, temp); } else if (nbr[1] != '0') { temp[0] = nbr[1]; temp[1] = '0'; tab = add_tab_str(tab, temp); } return (tab); } char **ft_number(char **tab, char *nbr) { int i; char *temp; i = 0; temp = malloc(2); temp[1] = '\0'; while (nbr[i]) { if (i == 0 && nbr[i] != '0') { temp[0] = nbr[i]; tab = add_tab_str(tab, temp); tab = add_tab_str(tab, "100"); } else if (i == 1) { if (nbr[i] == '1') i++; tab = i_is_1(tab, nbr); } if (i == 2 && nbr[i] != '0') { temp[0] = nbr[i]; tab = add_tab_str(tab, temp); } i++; } return (tab); } char *set_zeros(char *str) { int i; char *test; i = ft_strlen(str); if (i % 3 == 1) { str = ft_addchar(str, '0'); str = ft_addchar(str, '0'); } if (i % 3 == 2) { str = ft_addchar(str, '0'); } return (str); } char **ft_comp(char *str) { int i; int j; char *c; char **tab; tab = malloc(sizeof(char *)); c = malloc(4); c[3] = '\0'; j = 0; i = 0; while (str[i] != '\0') { j = 0; while (j < 3) { c[j] = str[i + j]; j++; } tab = ft_number(tab, c); i += 3; } return (tab); }