From 01adb845d959e74affab85b64b6fd6304cf48572 Mon Sep 17 00:00:00 2001 From: Axy Date: Thu, 30 Oct 2025 12:12:57 +0100 Subject: [PATCH] Various fixes --- ft_printf.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ft_printf.c b/ft_printf.c index 6ea6fc6..48b7309 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,7 +6,7 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/29 14:24:47 by agilliar #+# #+# */ -/* Updated: 2025/10/30 12:01:14 by agilliar ### ########.fr */ +/* Updated: 2025/10/30 12:12:46 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,13 @@ #include /* - Because of variadic argument promotion, we represent an expected char as an int + Because of variadic argument promotion, + we represent an expected char as an int */ typedef enum e_step { STEP_INT, - STEP_UNSIGNED, + STEP_UINT, STEP_PTR, STEP_NONE, } t_step; @@ -31,9 +32,9 @@ typedef enum e_step */ typedef union u_step_arg { - int v_int; - unsigned v_uint; - void *v_ptr; + int v_int; + unsigned int v_uint; + void *v_ptr; } t_step_arg; typedef enum e_sign_flag @@ -62,7 +63,7 @@ typedef enum e_specifier SPECIFIER_STRING, SPECIFIER_VOID_PTR, SPECIFIER_INT, - SPECIFIER_UNSIGNED, + SPECIFIER_UINT, SPECIFIER_INT_HEX_LOWER, SPECIFIER_INT_HEX_UPPER, SPECIFIER_PERCENT, @@ -71,7 +72,7 @@ typedef enum e_specifier typedef enum e_num_prefix { NUM_PREFIX_NONE, - NUM_PREFIX_FORMAT; + NUM_PREFIX_FORMAT, } t_num_prefix; typedef struct s_format @@ -81,7 +82,7 @@ typedef struct s_format t_justify justify; t_num_prefix num_prefix; size_t width; - s_padding_type padding_type; + t_padding_type padding_type; size_t precision; bool enable_precision; } t_format; @@ -97,7 +98,7 @@ t_format ft_format_default(void) res.justify = JUSTIFY_RIGHT; res.num_prefix = NUM_PREFIX_NONE; res.width = 0; - res.padding_type PADDING_SPACE; + res.padding_type = PADDING_SPACE; res.precision = 0; res.enable_precision = false; return (res); @@ -125,6 +126,9 @@ bool ft_parse_flag(char c, t_format *format) format->num_prefix = NUM_PREFIX_FORMAT; else if (c == '0') format->padding_type = PADDING_ZEROS; + else + return (false); + return (true); } t_specifier ft_parse_specifier(char c) @@ -138,7 +142,7 @@ t_specifier ft_parse_specifier(char c) if (c == 'd' || c == 'i') return (SPECIFIER_INT); if (c == 'u') - return (SPECIFIER_UNSIGNED); + return (SPECIFIER_UINT); if (c == 'x') return (SPECIFIER_INT_HEX_LOWER); if (c == 'X') @@ -148,7 +152,7 @@ t_specifier ft_parse_specifier(char c) return (SPECIFIER_NONE); } -t_format ft_parse_format(const char **format) +t_format ft_parse_format(const char **format) { t_format res; @@ -185,8 +189,8 @@ t_step specifier_to_step(t_specifier spec) return (STEP_NONE); if (spec == SPECIFIER_STRING || spec == SPECIFIER_VOID_PTR) return (STEP_PTR); - if (spec == SPECIFIER_UNSIGNED) - return (STEP_UNSIGNED); + if (spec == SPECIFIER_UINT) + return (STEP_UINT); return (STEP_INT); } @@ -209,7 +213,7 @@ int ft_printf(const char *format, ...) count += written; if (specifier_to_step(step.specifier) == STEP_INT) arg.v_int = va_arg(args, int); - if (specifier_to_step(step.specifier) == STEP_UNSIGNED) + if (specifier_to_step(step.specifier) == STEP_UINT) arg.v_uint = va_arg(args, unsigned); if (specifier_to_step(step.specifier) == STEP_PTR) arg.v_ptr = va_arg(args, void *); -- 2.51.0