-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr.c
52 lines (48 loc) · 1.32 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/08 20:25:03 by ohachim #+# #+# */
/* Updated: 2018/10/16 19:46:19 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_putnegative(int n)
{
if (n == -2147483648)
{
ft_putstr("-2147483648");
}
else
{
ft_putchar('-');
n = n * -1;
ft_putnbr(n);
}
}
void ft_putnbr(int n)
{
long int dec;
long int fn;
if (n < 0)
ft_putnegative(n);
else
{
fn = n;
dec = 1;
while (fn / 10 != 0)
{
dec = dec * 10;
fn = fn / 10;
}
while (dec > 0)
{
ft_putchar((n / dec) + '0');
n = n % dec;
dec = dec / 10;
}
}
}