diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-10-30 23:35:40 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-10-30 23:35:40 +0100 |
| commit | d63d6916249f5b40b81097854d8ca2c9d4d7d071 (patch) | |
| tree | b98fe6a060fdb632d00ddf9385f6579a32619f38 /convert_hex.c | |
| parent | 22f334a19cabebf10727d7894102946ba23d0e37 (diff) | |
| download | ft_printf-d63d6916249f5b40b81097854d8ca2c9d4d7d071.tar.gz ft_printf-d63d6916249f5b40b81097854d8ca2c9d4d7d071.tar.bz2 ft_printf-d63d6916249f5b40b81097854d8ca2c9d4d7d071.zip | |
Normed converters
Diffstat (limited to 'convert_hex.c')
| -rw-r--r-- | convert_hex.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/convert_hex.c b/convert_hex.c index 457b249..9826771 100644 --- a/convert_hex.c +++ b/convert_hex.c @@ -1,23 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_hex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:23:06 by cacharle #+# #+# */ +/* Updated: 2019/10/30 23:29:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include <stdarg.h> #include <stdlib.h> +#include "libft.h" #include "header.h" char *convert_hex(va_list ap, t_pformat *pformat) { - long long unsigned int n; + char *str; + char *tmp; + 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) + 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; str = ITOA_HEX_LOW(n); if (pformat->type == 'X') ft_strtoupper(str); @@ -30,7 +39,7 @@ char *convert_hex(va_list ap, t_pformat *pformat) } if (pformat->flags & FLAG_ALTERNATE && n != 0) { - char *tmp = ft_strjoin(pformat->type == 'X' ? "0X" : "0x", str); + tmp = ft_strjoin(pformat->type == 'X' ? "0X" : "0x", str); free(str); str = tmp; } |
