-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
executable file
·55 lines (51 loc) · 1.33 KB
/
ft_putnbr_fd.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: toramo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 09:47:19 by toramo #+# #+# */
/* Updated: 2023/10/30 09:48:28 by toramo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_abs(int n)
{
if (n < 0)
{
n = n * -1;
return (n);
}
else
{
return (n);
}
}
void ft_putnbr_fd(int nb, int fd)
{
int n;
char nbr[13];
n = 1;
if (nb < -2147483647)
{
write(fd, "-2147483648", 11);
return ;
}
if (nb < 0)
write(fd, "-", 1);
nb = ft_abs(nb);
nbr[0] = (nb % 10) + 48;
while (nb / 10 != 0)
{
nb = nb / 10;
nbr[n] = (nb % 10) + 48;
n++;
}
n--;
while (n >= 0)
{
write(fd, &nbr[n], 1);
n--;
}
}