-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr.c
40 lines (37 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cyfermie <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 16:16:00 by cyfermie #+# #+# */
/* Updated: 2017/11/07 16:16:09 by cyfermie ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putnbr(int n)
{
char tab[50];
unsigned short index;
unsigned int u;
index = 49;
u = (n < 0) ? ((unsigned int)-n) : ((unsigned int)n);
while (u > 0)
{
tab[index] = u % 10 + '0';
--index;
u = u / 10;
}
if (n < 0)
{
tab[index] = '-';
--index;
}
else if (n == 0)
{
tab[index] = '0';
--index;
}
write(STDOUT_FILENO, tab + index + 1, 49 - index);
}