-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
67 lines (59 loc) · 1.69 KB
/
ft_putnbr_fd.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jvico-ga <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/19 18:38:12 by jvico-ga #+# #+# */
/* Updated: 2021/10/30 16:02:09 by jvico-ga ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void check_sign(int n, long *numero, int fd);
static long return_long(int n);
void ft_putnbr_fd(int n, int fd)
{
char *string;
char c;
long numero;
size_t t;
int v;
check_sign(n, &numero, fd);
t = 0;
if (numero == 0)
t = 1;
while (numero > 0 && t++ != 20)
numero = numero / 10;
while (t-- > 0)
{
v = t;
numero = return_long(n);
while (v-- > 0)
numero = numero / 10;
c = (numero % 10) + 48;
string = &c;
write(fd, string, sizeof(char));
}
}
static void check_sign(int n, long *numero, int fd)
{
char c;
char *string;
*numero = n;
if (*numero < 0)
{
c = '-';
string = &c;
write(fd, string, sizeof(char));
*numero *= -1;
}
}
static long return_long(int n)
{
long numero_aux;
numero_aux = n;
if (numero_aux < 0)
numero_aux *= -1;
return (numero_aux);
}