aboutsummaryrefslogtreecommitdiff
path: root/convert_hex.c
diff options
context:
space:
mode:
Diffstat (limited to 'convert_hex.c')
-rw-r--r--convert_hex.c27
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;
}