/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_vprintf_decimal.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/20 11:55:02 by gbaconni #+# #+# */ /* Updated: 2022/04/29 09:09:08 by gbaconni ### lausanne.ch */ /* */ /* ************************************************************************** */ #include "libftprintf.h" int ft_vprintf_decimal(const char *format, va_list ap) { int ret; unsigned int u; int d; char *s; char c; ret = 0; c = *(format + ft_eoflags(format)); if (c == 'u') { u = va_arg(ap, unsigned int); s = ft_ltoa_base((long) u, "0123456789"); } else { d = va_arg(ap, int); s = ft_itoa(d); } const char *f; int flags; int precision; int len; precision = 0; flags = ft_vprintf_flags_bonus(format, ap); f = format; while (*f != '\0') { if (ft_isdigit(*f)) precision = precision * 10 + *f - '0'; if (ft_strchr(SPECIFIERS, *f) != NULL) break ; f++; } len = 0; if (precision > 0) { len = precision - ft_strlen(s); while (len-- > 0) { if (flags & F_ZERO) ret += ft_putchar('0'); else ret += ft_putchar(' '); } } ret += ft_puts(s); free(s); return (ret); }