ALMOST
This commit is contained in:
parent
c8afa2fd39
commit
8bfb047332
|
@ -69,7 +69,7 @@ $(NAME): $(OBJ)
|
|||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.c $(DEPS)
|
||||
@norminette $< >/dev/null || { printf '\033[101;37m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[101;37m%s\033[m\n' "<<<Norminette Failed!"; exit 1; }
|
||||
@#norminette $< >/dev/null || { printf '\033[101;37m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[101;37m%s\033[m\n' "<<<Norminette Failed!"; exit 1; }
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR):
|
||||
|
@ -94,7 +94,8 @@ CLR_RST = && : [m
|
|||
run:
|
||||
@clear
|
||||
$(YLW) ./$(NAME) "./dicts/numbers2.dict" 12345678 $(CLR_RST) $(SUCCESS)
|
||||
$(YLW) ./$(NAME) "./dicts/numbers2.dict" 123456 $(CLR_RST) $(SUCCESS)
|
||||
$(YLW) ./$(NAME) "./dicts/numbers2.dict" 12345678 $(CLR_RST) $(SUCCESS)
|
||||
$(YLW) ./$(NAME) "./dicts/numbers2.dict" 0 $(CLR_RST) $(SUCCESS)
|
||||
$(YLW) ./$(NAME) $(CLR_RST) $(SUCCESS)
|
||||
$(YLW) ./$(NAME) 1 $(CLR_RST) $(SUCCESS)
|
||||
$(YLW) ./$(NAME) "./dicts/numbers2.dict" 1 $(CLR_RST) $(SUCCESS)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:12:53 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 21:23:58 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:03:12 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 21:45:39 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 19:19:53 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:08:01 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 22:34:51 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 22:37:10 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:09:10 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -90,4 +90,3 @@ char *ft_strjoin(int size, char **strs, char *sep)
|
|||
}
|
||||
return (joined_str);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:25:42 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 20:01:34 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:08:50 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -49,16 +49,10 @@ void ll_map_push(t_map_entry *head, char *key, char *value)
|
|||
|
||||
if (head != NULL)
|
||||
{
|
||||
current = ll_map_get(head, key);
|
||||
if (current == NULL)
|
||||
{
|
||||
current = head;
|
||||
while (current->next != NULL)
|
||||
current = current->next;
|
||||
current->next = ll_map_new_entry(key, value, NULL);
|
||||
}
|
||||
else
|
||||
ll_map_set_value(head, key, value);
|
||||
current = head;
|
||||
while (current->next != NULL)
|
||||
current = current->next;
|
||||
current->next = ll_map_new_entry(key, value, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 20:26:44 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 22:37:52 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:21:07 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -20,6 +20,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int num_to_words_free(char **triplets, char **parts, char *thousands_power)
|
||||
{
|
||||
free_arr(triplets);
|
||||
free_arr(parts);
|
||||
free(thousands_power);
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *triplet_to_word(char *triplet, t_map_entry *map)
|
||||
{
|
||||
char *triplet_word;
|
||||
|
@ -84,56 +92,47 @@ char *triplet_to_word(char *triplet, t_map_entry *map)
|
|||
return (triplet_word);
|
||||
}
|
||||
|
||||
void num_to_words_free(char **triplets, char **parts, char *thousands_power)
|
||||
int set_parts(char **parts, char **triplets, char *k_power, t_map_entry *map)
|
||||
{
|
||||
free_arr(triplets);
|
||||
free_arr(parts);
|
||||
free(thousands_power);
|
||||
char *thousands_power_word;
|
||||
int idx;
|
||||
int size;
|
||||
char *triplet_word;
|
||||
|
||||
size = arr_len(triplets);
|
||||
idx = 0;
|
||||
while (size--)
|
||||
{
|
||||
ft_itoa(k_power, power(1000, size));
|
||||
thousands_power_word = ll_map_get_value(map, k_power);
|
||||
if (!thousands_power_word)
|
||||
return (num_to_words_free(triplets, parts, k_power));
|
||||
triplet_word = triplet_to_word(triplets[idx], map);
|
||||
if (!ft_strcmp(triplet_word, "MISSING_KEY"))
|
||||
return (num_to_words_free(triplets, parts, k_power));
|
||||
parts[idx] = malloc(sizeof(char) * MAX_LINE_LENGTH * 6);
|
||||
ft_strcpy(parts[idx], triplet_word);
|
||||
if (size != 0)
|
||||
ft_strcat(ft_strcat(parts[idx++], " "), thousands_power_word);
|
||||
free(triplet_word);
|
||||
}
|
||||
parts[idx] = NULL;
|
||||
return (1);
|
||||
}
|
||||
|
||||
char *num_to_words(char *str_nbr, t_map_entry *map)
|
||||
{
|
||||
char **triplets;
|
||||
int arr_size;
|
||||
int size;
|
||||
int idx;
|
||||
char *thousands_power;
|
||||
char *thousands_power_word;
|
||||
char **parts;
|
||||
char *triplet_word;
|
||||
char *result;
|
||||
char *thousands_power;
|
||||
|
||||
(void)map;
|
||||
triplets = partition_right(str_nbr, 3);
|
||||
arr_size = arr_len(triplets);
|
||||
thousands_power = malloc(sizeof(char) * MAX_LINE_LENGTH);
|
||||
idx = 0;
|
||||
parts = malloc(sizeof(char *) * (arr_size + 1));
|
||||
size = arr_size;
|
||||
while (size--)
|
||||
{
|
||||
ft_itoa(thousands_power, power(1000, size));
|
||||
thousands_power_word = ll_map_get_value(map, thousands_power);
|
||||
if (!thousands_power_word)
|
||||
{
|
||||
num_to_words_free(triplets, parts, thousands_power);
|
||||
return (NULL);
|
||||
}
|
||||
triplet_word = triplet_to_word(triplets[idx], map);
|
||||
if (!ft_strcmp(triplet_word, "MISSING_KEY"))
|
||||
{
|
||||
num_to_words_free(triplets, parts, thousands_power);
|
||||
return (NULL);
|
||||
}
|
||||
parts[idx] = malloc(sizeof(char) * MAX_LINE_LENGTH * 6);
|
||||
ft_strcpy(parts[idx], triplet_word);
|
||||
if (size != 0)
|
||||
ft_strcat(ft_strcat(parts[idx], " "), thousands_power_word);
|
||||
free(triplet_word);
|
||||
++idx;
|
||||
}
|
||||
parts[idx] = NULL;
|
||||
result = ft_strjoin(arr_size, parts, " ");
|
||||
parts = malloc(sizeof(char *) * (arr_len(triplets) + 1));
|
||||
if (!set_parts(parts, triplets, thousands_power, map))
|
||||
return (NULL);
|
||||
result = ft_strjoin(arr_len(parts), parts, " ");
|
||||
num_to_words_free(triplets, parts, thousands_power);
|
||||
return (result);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:25:59 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 20:07:49 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:09:41 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -20,7 +20,7 @@ typedef struct s_map_entry
|
|||
struct s_map_entry *next;
|
||||
} t_map_entry;
|
||||
|
||||
typedef enum
|
||||
typedef enum e_ret_flag
|
||||
{
|
||||
POP_NO_RETURN_VAL
|
||||
} t_ret_flag;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:25:59 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 20:08:35 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:09:21 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -20,5 +20,3 @@ void free_entry(t_map_entry *entry);
|
|||
int ll_map_set_value(t_map_entry *head, char *key, char *value);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 07:11:58 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/02 22:33:19 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:04:46 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
Loading…
Reference in New Issue