diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-10-30 04:58:00 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-10-30 04:58:00 +0100 |
| commit | 001786c8ec464b1ae3e6321acfd984227cb1bbee (patch) | |
| tree | 6c71dd227eb8a8c28cd529cb4cfc31879e845831 /convert_hex_low.c | |
| parent | d963161275bcb3af4097872ba033da3ff9255606 (diff) | |
| download | ft_printf-001786c8ec464b1ae3e6321acfd984227cb1bbee.tar.gz ft_printf-001786c8ec464b1ae3e6321acfd984227cb1bbee.tar.bz2 ft_printf-001786c8ec464b1ae3e6321acfd984227cb1bbee.zip | |
Added flags for x and X
Diffstat (limited to 'convert_hex_low.c')
| -rw-r--r-- | convert_hex_low.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/convert_hex_low.c b/convert_hex_low.c index 39cc188..00b2d76 100644 --- a/convert_hex_low.c +++ b/convert_hex_low.c @@ -1,17 +1,37 @@ #include <stdarg.h> +#include <stdlib.h> #include "header.h" char *convert_hex_low(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_LOW(n); str = handle_precision(pformat, str); + 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); } |
