diff options
Diffstat (limited to 'c04/ex02')
| -rw-r--r-- | c04/ex02/ft_putnbr.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/06 07:24:04 by cacharle #+# #+# */ +/* Updated: 2019/07/06 08:34:48 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +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'); + } +} |
