-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
58 lines (53 loc) · 1.42 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
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jinsyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/22 15:45:38 by jinsyang #+# #+# */
/* Updated: 2022/11/22 16:47:40 by jinsyang ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void numprint(int n, int fd, int flag)
{
char p[11];
int count;
count = 0;
while (n != 0)
{
p[count] = n % 10 + '0';
n /= 10;
count++;
}
p[count] = '\0';
--count;
if (flag == 1)
p[0]++;
while (count >= 0)
{
write(fd, &p[count], 1);
count--;
}
}
void ft_putnbr_fd(int n, int fd)
{
int flag;
flag = 0;
if (n == 0)
write(fd, "0", 1);
else if (n == -2147483648)
{
flag++;
n++;
n *= -1;
write(fd, "-", 1);
}
else if (0 > n && n > -2147483648)
{
n *= -1;
write(fd, "-", 1);
}
numprint(n, fd, flag);
}