-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_utils.c
79 lines (71 loc) · 1.63 KB
/
ft_printf_utils.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
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aantonie <aantonie@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/15 14:27:01 by aantonie #+# #+# */
/* Updated: 2024/02/15 14:30:14 by aantonie ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putstr_fd(char *s)
{
if (!s)
write(1, "null", 6);
while (*s)
{
write(1, s, 1);
s++;
}
}
int ft_printpercent(void)
{
write(1, "%", 1);
return (1);
}
int ft_printstr(char *str)
{
int i;
i = 0;
if (str == NULL)
{
ft_putstr_fd("(null)");
return (6);
}
while (str[i])
{
write(1, &str[i], 1);
i++;
}
return (i);
}
int ft_putnbr_fd(long n, int fd)
{
int length;
length = 0;
if (n == -2147483648)
{
write(fd, "-2147483648", 11);
return (11);
}
if (n < 0)
{
ft_putchar_fd('-', fd);
n = -n;
length++;
}
if (n >= 10)
{
length += ft_putnbr_fd(n / 10, fd);
}
ft_putchar_fd((char)(n % 10 + '0'), fd);
length++;
return (length);
}
int ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
return (1);
}