aboutsummaryrefslogtreecommitdiff
path: root/c04/ex02/ft_putnbr.c
blob: 8a13dc590fdea874cc985aabc7f684a7cb5132d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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');
	}
}