]> Untitled Git - axy/ft/ft_printf.git/commitdiff
Partial ptr and full str impl
author= <=>
Thu, 30 Oct 2025 16:44:02 +0000 (17:44 +0100)
committer= <=>
Thu, 30 Oct 2025 16:44:02 +0000 (17:44 +0100)
a.out
ft_printf.c

diff --git a/a.out b/a.out
index 5fa0ae84acb03c21d3f734698e4e1effaa4f014d..ca9f290f50836fbcd34869914a75dfde390904ea 100755 (executable)
Binary files a/a.out and b/a.out differ
index ac6b3951c4f87bbc107267e172ad6ec37a07c43f..d2817f51040b933b3a630b239ddda7965ae2bfc8 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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 <stdio.h>
 int    main(void)
 {
-       ft_printf("c%-10s", NULL);
+       const char      *s = "hai";
+       ft_printf("c%-10.2s", s);
+       printf("c%-10.2s", s);
 }