aboutsummaryrefslogtreecommitdiff
path: root/utils.c
blob: 148416585fd55d29b9e74dc01a4e5de82b36ce39 (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
#include <unistd.h>
#include "ft_printf.h"

void	ft_putchar(char c)
{
	write(STDOUT_FILENO, &c, 1);
}

void	ft_putstr(char *str)
{
	while (*str)
		write(STDOUT_FILENO, str++, 1);
}

void	ft_putnbr(int n)
{
	unsigned int	p_n;

	p_n = n;
	if (n < 0)
	{
		ft_putchar('-');
		p_n = -n;
	}
	if (p_n > 9)
		ft_putnbr(p_n / 10);
	ft_putchar(p_n % 10 + '0');
}

void	ft_putxnbr(unsigned int n, char *hex_symbols)
{
	if (n > 15)
		ft_putxnbr(n / 16, hex_symbols);
	ft_putchar(hex_symbols[n % 16]);
}

void	ft_putunbr(unsigned int n)
{
	if (n > 9)
		ft_putunbr(n / 10);
	ft_putchar(n % 10 + '0');
}