/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_printf.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/27 08:09:49 by narnaud #+# #+# */ /* Updated: 2021/11/17 09:40:16 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "ft_printf.h" int ft_printf(const char *str, ...) { va_list args; size_t n; size_t i; const char *g_types = {"cspdiuxX%"}; static int (*g_printf_fcts[9])(va_list arg, const char *str) = {\ va_putchar, va_putstr, va_putptr, va_putnbr, va_putnbr, va_putunsign, \ va_putx, va_putx_cap, va_putperc}; i = 0; va_start (args, str); while (*str) { n = -1; if ((*str == '%' && str++) || !(++i && ft_putchar((int)*str))) while (++n < 9) if (g_types[n] == *str) i += (g_printf_fcts[n])(args, str); str++; } va_end(args); return (i); }