/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_printf.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/13 10:48:34 by grobledo #+# #+# */ /* Updated: 2023/03/13 10:48:35 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_format(const char format, va_list args, int count) { if (format == 'c') count = ft_putcharf((char)va_arg(args, int), count); else if (format == 's') count = ft_putstrf(va_arg(args, char *), count); else if (format == 'd') count = ft_putnbrf(va_arg(args, int), count); else if (format == 'i') count = ft_putnbrf(va_arg(args, int), count); else if (format == 'u') count = ft_putnbrposf(va_arg(args, unsigned int), count); else if (format == 'x') count = ft_starthexa (va_arg(args, unsigned int), 'x', count); else if (format == 'X') count = ft_starthexa (va_arg(args, unsigned int), 'X', count); else if (format == 'p') count = ft_startpointer (va_arg(args, unsigned long long int), 'p', count); else if (format == '%') count = ft_putcharf('%', count); return (count); } int ft_printf(const char *format, ...) { va_list args; int i; int count; va_start(args, format); i = 0; count = 0; while (format[i]) { if (format[i] != '%') { write(1, &format[i], 1); count++; } else { i++; count = ft_format(format[i], args, count); } i++; } va_end(args); return (count); }