-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr.c
executable file
·38 lines (35 loc) · 1.3 KB
/
ft_putnbr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: istalevs <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/13 14:08:09 by istalevs #+# #+# */
/* Updated: 2017/12/13 12:37:43 by istalevs ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr(int n)
{
char x;
int tmp;
int count;
int size;
tmp = n;
count = 1;
size = 0;
while (++size && (tmp /= 10) != 0)
count *= 10;
if (n < 0)
{
ft_putchar(45);
while (size-- && (x = 48 - n / count) != 0 && write(1, &x, 1))
if (n += (x - 48) * count)
count /= 10;
}
else
while (size-- && (x = 48 + n / count) != 0 && write(1, &x, 1))
if (n -= (x - 48) * count)
count /= 10;
}