-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr.c
53 lines (48 loc) · 1.35 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
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: azaher <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/30 18:14:47 by azaher #+# #+# */
/* Updated: 2022/10/31 15:55:33 by azaher ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_countdigits(int n)
{
int count;
count = 0;
if (n <= 0)
count++;
while (n != 0)
{
n = n / 10;
count++;
}
return (count);
}
int ft_putnbr(int n)
{
int count;
count = ft_countdigits(n);
if (n == -2147483648)
{
ft_putstr("-2");
n = 147483648;
}
if (n >= 0 && n <= 9)
ft_putchar(n + '0');
else if (n < 0)
{
ft_putchar('-');
ft_putnbr(n * (-1));
}
else
{
ft_putnbr(n / 10);
ft_putnbr(n % 10);
}
return (count);
}