-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
51 lines (46 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: guferrei <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/26 20:42:17 by guferrei #+# #+# */
/* Updated: 2021/05/28 19:22:34 by guferrei ### ########.fr */
/* */
/* ************************************************************************** */
#include<unistd.h>
unsigned int signal(int n, int fd)
{
unsigned int nb;
if (n < 0)
{
write(fd, "-", 1);
nb = n * -1;
}
else
nb = n;
return (nb);
}
void ft_putnbr_fd(int n, int fd)
{
char str[11];
char *ptr;
int c;
unsigned int nb;
c = 0;
ptr = &str[0];
nb = signal(n, fd);
while (nb > 9)
{
*(ptr + c) = (nb % 10) + 48;
nb = nb / 10;
c++;
}
*(ptr + c) = nb + 48;
while (c >= 0)
{
write(fd, &*(ptr + c), 1);
c--;
}
}