ft_printf/ft_putnbrhex_upper.c
Etienne Rey-bethbeder 95b7ca347f Fini printf
2022-11-21 19:33:11 +01:00

42 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrhex_upper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/14 23:24:36 by erey-bet #+# #+# */
/* Updated: 2022/11/21 19:16:57 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbrhex_upper(unsigned int v)
{
int tmp;
int count;
char hex[100];
if (v == 0)
{
ft_putchar('0');
return (1);
}
count = 0;
tmp = 0;
while (v > 0)
{
tmp = v % 16;
if (tmp < 10)
hex[count++] = (tmp + 48);
else
hex[count++] = (tmp + 55);
v = v / 16;
}
tmp = count;
while (--tmp >= 0)
ft_putchar(hex[tmp]);
return (count);
}