Bonus first try

This commit is contained in:
gbaconni
2022-04-26 17:53:39 +02:00
parent 2a2f6f3a9d
commit d9fc240b0e
10 changed files with 115 additions and 45 deletions

View File

@@ -6,7 +6,7 @@
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/20 11:55:02 by gbaconni #+# #+# */
/* Updated: 2022/04/16 01:19:09 by gbaconni ### lausanne.ch */
/* Updated: 2022/04/26 17:48:37 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,9 +18,11 @@ int ft_vprintf_decimal(const char *format, va_list ap)
unsigned int u;
int d;
char *s;
char c;
(void) format;
if (*format == 'u')
ret = 0;
c = *(format + ft_eoflags(format));
if (c == 'u')
{
u = va_arg(ap, unsigned int);
s = ft_ltoa_base((long) u, "0123456789");
@@ -30,7 +32,36 @@ int ft_vprintf_decimal(const char *format, va_list ap)
d = va_arg(ap, int);
s = ft_itoa(d);
}
ret = ft_puts(s);
const char *f;
int flags;
int precision;
int len;
precision = 0;
flags = ft_vprintf_flags_bonus(format, ap);
f = format;
while (*f != '\0')
{
if (*f >= '0' && *f <= '9')
precision = precision * 10 + *f - '0';
if (*f == 'c' || *f == 's' || *f == 'p' || *f == 'd' || *f == 'i' || *f == 'u' || *f == 'x' || *f == 'X' || *f == '%')
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);
}