diff options
| author | Dominik Kaiser | 2024-03-18 11:37:50 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2024-03-18 11:37:50 +0100 |
| commit | 0fb01c961c92e54e04ad4c7881805db597089863 (patch) | |
| tree | 2b2d020d4175694347da55070c4f52985eacf697 /ft_printhex.c | |
| parent | b3bb3f0889cb01e6a1064a13b718f623bdc5a1e2 (diff) | |
| download | ft_printf-0fb01c961c92e54e04ad4c7881805db597089863.tar.gz ft_printf-0fb01c961c92e54e04ad4c7881805db597089863.zip | |
Remove the src dir and put everything in root dir
hoping that it will appease moulinette
Diffstat (limited to 'ft_printhex.c')
| -rw-r--r-- | ft_printhex.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ft_printhex.c b/ft_printhex.c new file mode 100644 index 0000000..d65de1c --- /dev/null +++ b/ft_printhex.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printhex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 15:50:35 by dkaiser #+# #+# */ +/* Updated: 2024/03/15 12:40:38 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../ft_printf.h" + +static void printhex_rec(unsigned int nbr, char fmt, int *len) +{ + char c; + int success; + + if (*len < 0) + return ; + if (nbr % 16 < 10) + c = '0' + (nbr % 16); + else + c = (fmt - 33) + (nbr % 16); + if (nbr > 15) + printhex_rec(nbr / 16, fmt, len); + if (*len < 0) + return ; + success = write(1, &c, 1); + if (success < 0) + *len = -1; + else + (*len)++; +} + +int ft_printhex(unsigned int nbr, char fmt) +{ + int len; + + len = 0; + printhex_rec(nbr, fmt, &len); + return (len); +} |
