-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putnbr.c
More file actions
52 lines (48 loc) · 1.32 KB
/
ft_putnbr.c
File metadata and controls
52 lines (48 loc) · 1.32 KB
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: jsprouts <jsprouts@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/25 05:26:23 by jsprouts #+# #+# */
/* Updated: 2019/09/25 05:52:57 by jsprouts ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_check(int *nb)
{
if (*nb == -2147483647 - 1)
{
*nb += 1;
return (1);
}
return (0);
}
void ft_putnbr(int n)
{
int index;
char str[11];
int i;
i = ft_check(&n);
if (n == 0)
{
ft_putchar('0');
return ;
}
if (n < 0)
{
ft_putchar('-');
n = -n;
}
index = 0;
while (n > 0)
{
str[index++] = (n % 10) + '0';
n /= 10;
}
if (i)
str[0] = '8';
while (index > 0)
ft_putchar(str[--index]);
}