-
Notifications
You must be signed in to change notification settings - Fork 0
/
libfthelp.c
67 lines (60 loc) · 1.46 KB
/
libfthelp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libfthelp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/25 21:05:14 by vsimeono #+# #+# */
/* Updated: 2021/11/27 22:12:05 by vsimeono ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
void ft_putnbr_fd(int n, int fd)
{
int temp;
temp = n;
if (n == -2147483648)
{
ft_putstr_fd("-2147483648", fd);
return ;
}
if (temp < 0)
{
ft_putchar_fd('-', fd);
temp *= -1;
}
if (temp < 10)
{
ft_putchar_fd(temp + '0', fd);
}
else
{
ft_putnbr_fd(temp / 10, fd);
ft_putnbr_fd(temp % 10, fd);
}
}
void ft_putstr_fd(char *s, int fd)
{
if (s)
{
while (*s)
{
write(fd, s++, 1);
}
}
}
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}