From 001786c8ec464b1ae3e6321acfd984227cb1bbee Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 30 Oct 2019 04:58:00 +0100 Subject: Added flags for x and X --- convert_hex_up.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'convert_hex_up.c') diff --git a/convert_hex_up.c b/convert_hex_up.c index 7f5e640..eba1226 100644 --- a/convert_hex_up.c +++ b/convert_hex_up.c @@ -1,17 +1,37 @@ #include +#include #include "header.h" char *convert_hex_up(va_list ap, t_pformat *pformat) { - unsigned int n = va_arg(ap, unsigned int); + long long unsigned int n; + + if (pformat->flags & FLAG_SHORT) + n = va_arg(ap, int); + else if (pformat->flags & FLAG_SHORT_SHORT) + n = va_arg(ap, int); + else if (pformat->flags & FLAG_LONG) + n = va_arg(ap, long unsigned int); + else if (pformat->flags & FLAG_LONG_LONG) + n = va_arg(ap, long long unsigned int); + else + n = va_arg(ap, unsigned int); + char *str = ITOA_HEX_UP(n); str = handle_precision(pformat, str); - if (pformat->flags & FLAG_ALTERNATE) + if (pformat->flags & FLAG_ZERO_PADDING) + { + if (pformat->flags & FLAG_ALTERNATE && n != 0) + pformat->min_width -= 2; + str = handle_padding(pformat, str); + } + if (pformat->flags & FLAG_ALTERNATE && n != 0) { char *tmp = ft_strjoin("0X", str); free(str); str = tmp; } - str = handle_padding(pformat, str); + if (!(pformat->flags & FLAG_ZERO_PADDING)) + str = handle_padding(pformat, str); return (str); } -- cgit