-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
50 lines (46 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rodrodri <[email protected] > +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 00:38:52 by rodrodri #+# #+# */
/* Updated: 2021/11/14 19:58:45 by rodrodri ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
int positions;
if (n == -2147483648)
{
ft_putstr_fd("-2", fd);
n = 147483648;
}
if (n < 0)
{
ft_putchar_fd('-', fd);
n *= -1;
}
positions = 1;
while (n / positions >= 10)
positions *= 10;
while (positions >= 1)
{
ft_putchar_fd((n / positions) % 10 + '0', fd);
positions /= 10;
}
}
/* It would have been nice... (if malloc were allowed)
**{
** char *s;
**
** s = ft_itoa(n);
** if (s)
** {
** ft_putstr_fd(s, fd);
** ft_strdel(&s);
** }
**}
*/