-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr.c
39 lines (36 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oqaroot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/01 20:39:15 by oqaroot #+# #+# */
/* Updated: 2024/08/04 12:39:37 by oqaroot ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbr(int n)
{
int len;
char num[12];
int i;
i = 11;
len = 0;
num[i--] = '\0';
if (n == 0)
return (ft_putchar('0'));
if (n == -2147483648)
return (ft_putstr("-2147483648"));
if (n < 0)
{
len += ft_putchar('-');
n = -n;
}
while (n)
{
num[i--] = (n % 10) + '0';
n /= 10;
}
return (len + ft_putstr(&num[i + 1]));
}