-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putnbr_fd.c
More file actions
52 lines (48 loc) · 1.35 KB
/
ft_putnbr_fd.c
File metadata and controls
52 lines (48 loc) · 1.35 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_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jsprouts <jsprouts@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/25 06:00:50 by jsprouts #+# #+# */
/* Updated: 2019/09/25 06:08:23 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_fd(int n, int fd)
{
int index;
char str[11];
int i;
i = ft_check(&n);
if (n == 0)
{
ft_putchar_fd('0', fd);
return ;
}
if (n < 0)
{
ft_putchar_fd('-', fd);
n = -n;
}
index = 0;
while (n > 0)
{
str[index++] = (n % 10) + '0';
n /= 10;
}
if (i)
str[0] = '8';
while (index > 0)
ft_putchar_fd(str[--index], fd);
}