-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putnbr_fd.c
More file actions
51 lines (44 loc) · 1.39 KB
/
ft_putnbr_fd.c
File metadata and controls
51 lines (44 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lcosta-g <lcosta-g@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/09 13:17:49 by lcosta-g #+# #+# */
/* Updated: 2024/10/26 15:34:52 by lcosta-g ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void write_number(long long n, int fd)
{
char c;
if (n > 9)
write_number(n / 10, fd);
c = (n % 10) + '0';
ft_putchar_fd(c, fd);
}
void ft_putnbr_fd(int n, int fd)
{
long long long_n;
long_n = n;
if (long_n < 0)
{
long_n = -long_n;
ft_putchar_fd('-', fd);
}
write_number(long_n, fd);
}
/*
#include <fcntl.h>
int main(void)
{
int fd;
fd = open("testfile.txt", O_WRONLY);
ft_putnbr_fd(-2147483648, fd);
ft_putnbr_fd(0, fd);
ft_putnbr_fd(2147483647, fd);
close(fd);
return (0);
}
*/