-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_put.c
79 lines (69 loc) · 1.67 KB
/
ft_put.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rsebasti <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 09:25:05 by rsebasti #+# #+# */
/* Updated: 2024/11/12 09:31:48 by rsebasti ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int putchars(int c)
{
write(1, &c, 1);
return (1);
}
int putstrs(char *s)
{
int i;
i = 0;
if (s == NULL)
return (putstrs("(null)"));
while (s[i])
{
putchars(s[i]);
i++;
}
return (i);
}
int putnbrs(int n)
{
long nb;
int i;
nb = n;
i = 0;
if (nb < 0)
{
i += putchars('-');
nb = -nb;
}
if (nb > 9)
i += putnbrs(nb / 10);
i += putchars(nb % 10 + 48);
return (i);
}
int putunbrs(unsigned int n)
{
int i;
i = 0;
if (n > 9)
i += putnbrs(n / 10);
i += putchars(n % 10 + 48);
return (i);
}
int puthexa(unsigned long nb, int ismaj)
{
char *hexa;
int i;
i = 0;
hexa = "0123456789abcdef";
if (nb > 15)
i += puthexa(nb / 16, ismaj);
if (nb % 16 > 9 && ismaj == 1)
i += putchars(hexa[nb % 16] - 32);
else
i += putchars(hexa[nb % 16]);
return (i);
}