From: = <=> Date: Thu, 30 Oct 2025 16:44:02 +0000 (+0100) Subject: Partial ptr and full str impl X-Git-Tag: Testable~10 X-Git-Url: https://git.uwuaxy.net/?a=commitdiff_plain;h=ccbffa5a2163ee448a6269f53430c6a5316afe35;p=axy%2Fft%2Fft_printf.git Partial ptr and full str impl --- diff --git a/a.out b/a.out index 5fa0ae8..ca9f290 100755 Binary files a/a.out and b/a.out differ diff --git a/ft_printf.c b/ft_printf.c index ac6b395..d2817f5 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 17:33:02 by agilliar ### ########.fr */ +/* Updated: 2025/10/30 17:42:47 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,8 +59,8 @@ typedef enum e_specifier { SPECIFIER_NONE, SPECIFIER_CHAR, - SPECIFIER_STRING, - SPECIFIER_VOID_PTR, + SPECIFIER_STR, + SPECIFIER_PTR, SPECIFIER_INT, SPECIFIER_UINT, SPECIFIER_UINT_HEX_LOWER, @@ -125,6 +125,19 @@ int ft_putformat_str(const t_format *format, t_step_arg arg, bool simulated) return (i); } +int ft_putformat_ptr(const t_format *format, t_step_arg arg, bool simulated) +{ + t_format format2; + + if (!arg.v_ptr) + { + format2 = *format; + format2.specifier = SPECIFIER_STR; + arg.v_ptr = "(nil)"; + return (ft_putformat_str(&format2, arg, simulated)); + } +} + int ft_putformat(const t_format *format, t_step_arg arg) { int (*f)(const t_format *, t_step_arg, bool); @@ -132,8 +145,10 @@ int ft_putformat(const t_format *format, t_step_arg arg) if (format->specifier == SPECIFIER_CHAR) f = ft_putformat_char; - else if (format->specifier == SPECIFIER_STRING) + else if (format->specifier == SPECIFIER_STR) f = ft_putformat_str; + else if (format->specifier == SPECIFIER_PTR) + f = ft_putformat_ptr; else return (-1); len = f(format, arg, true); @@ -215,9 +230,9 @@ t_specifier ft_parse_specifier(char c) if (c == 'c') return (SPECIFIER_CHAR); if (c == 's') - return (SPECIFIER_STRING); + return (SPECIFIER_STR); if (c == 'p') - return (SPECIFIER_VOID_PTR); + return (SPECIFIER_PTR); if (c == 'd' || c == 'i') return (SPECIFIER_INT); if (c == 'u') @@ -266,7 +281,7 @@ t_step specifier_to_step(t_specifier spec) { if (spec == SPECIFIER_NONE || spec == SPECIFIER_PERCENT) return (STEP_NONE); - if (spec == SPECIFIER_STRING || spec == SPECIFIER_VOID_PTR) + if (spec == SPECIFIER_STR || spec == SPECIFIER_PTR) return (STEP_PTR); if (spec == SPECIFIER_UINT) return (STEP_UINT); @@ -301,7 +316,10 @@ int ft_printf(const char *s, ...) return (count); } +#include int main(void) { - ft_printf("c%-10s", NULL); + const char *s = "hai"; + ft_printf("c%-10.2s", s); + printf("c%-10.2s", s); }