-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_utils.c
More file actions
57 lines (50 loc) · 1.5 KB
/
ft_utils.c
File metadata and controls
57 lines (50 loc) · 1.5 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
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amarjan <amarjan@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/18 12:09:38 by amarjan #+# #+# */
/* Updated: 2026/01/18 12:09:49 by amarjan ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar_fd(char c, int fd)
{
return (write(fd, &c, 1));
}
int ft_strlen(const char *s)
{
int len;
len = 0;
while (s[len] != '\0')
len++;
return (len);
}
int ft_putstr_fd(char *s, int fd)
{
if (!s)
return (write(1, "(null)", 6));
return (write(fd, s, ft_strlen(s)));
}
int ft_putnbr_fd(int n, int fd)
{
int sign;
sign = 0;
if (n == -2147483648)
{
return (write(fd, "-2147483648", 11));
}
if (n < 0)
{
write(fd, "-", 1);
n = -n;
sign = 1;
}
if (n <= 9)
{
return (ft_putchar_fd(n + 48, fd) + sign);
}
return (sign + ft_putnbr_fd(n / 10, fd) + ft_putchar_fd(n % 10 + 48, fd));
}