-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putnbr_fd.c
More file actions
40 lines (37 loc) · 1.34 KB
/
ft_putnbr_fd.c
File metadata and controls
40 lines (37 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jowagner <jowagner@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 18:30:27 by jowagner #+# #+# */
/* Updated: 2024/11/29 19:01:40 by jowagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Writes an integer to the given file descriptor.
*
* @param n The integer to be written.
* @param fd The file descriptor to write to (1 for standard output,
* 2 for standard error, etc.).
*/
void ft_putnbr_fd(int n, int fd)
{
int num;
if (n == INT_MIN1)
{
ft_putstr_fd(INT_MINSTR, fd);
return ;
}
if (n < 0)
{
ft_putchar_fd('-', fd);
n = -n;
}
if (n > 9)
ft_putnbr_fd(n / 10, fd);
num = (n % 10) + '0';
write(fd, &num, 1);
}