/* 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 */
/* */
/* ************************************************************************** */
{
SPECIFIER_NONE,
SPECIFIER_CHAR,
- SPECIFIER_STRING,
- SPECIFIER_VOID_PTR,
+ SPECIFIER_STR,
+ SPECIFIER_PTR,
SPECIFIER_INT,
SPECIFIER_UINT,
SPECIFIER_UINT_HEX_LOWER,
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);
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);
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')
{
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);
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);
}