From 244f5209ba7885daa513e3780b66df454422b910 Mon Sep 17 00:00:00 2001 From: Cabergs Charles Date: Sat, 6 Jul 2019 08:42:30 +0200 Subject: c03 and begin c04 --- c04/ex02/ft_putnbr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 c04/ex02/ft_putnbr.c (limited to 'c04/ex02') diff --git a/c04/ex02/ft_putnbr.c b/c04/ex02/ft_putnbr.c new file mode 100644 index 0000000..8a13dc5 --- /dev/null +++ b/c04/ex02/ft_putnbr.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/06 07:24:04 by cacharle #+# #+# */ +/* Updated: 2019/07/06 08:34:48 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr(int nb) +{ + int i; + int rev_digits[100]; + unsigned int nbu; + + if (nb < 0) + { + ft_putchar('-'); + nbu = -nb; + } else + nbu = nb; + i = 0; + while (nbu > 0) + { + rev_digits[i] = nbu % 10; + nbu /= 10; + i++; + } + while (i > 0) + { + i--; + ft_putchar(rev_digits[i] + '0'); + } +} -- cgit