-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_put.c
94 lines (84 loc) · 1.95 KB
/
ft_put.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sasano <sasano.stu> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/09 19:12:07 by sasano #+# #+# */
/* Updated: 2023/11/17 18:44:39 by sasano ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(unsigned char c)
{
write(1, &c, 1);
return (1);
}
int ft_putstr(char *str)
{
int i;
i = 0;
if (str == NULL)
{
ft_putstr("(null)");
return (6);
}
while (str[i])
{
ft_putchar(str[i]);
i++;
}
return (i);
}
int ft_putnbr(int nb)
{
int count;
count = 0;
if (nb == -2147483648)
{
count += ft_putstr("-2147483648");
return (count);
}
if (nb < 0)
{
count += ft_putchar('-');
nb *= -1;
}
if (nb >= 10)
{
count += ft_putnbr(nb / 10);
count += ft_putnbr(nb % 10);
}
else
count += ft_putchar(nb + '0');
return (count);
}
int ft_putnbr_unsigned(unsigned int nb)
{
int count;
count = 0;
if (nb >= 10)
{
count += ft_putnbr(nb / 10);
count += ft_putnbr(nb % 10);
}
else
count += ft_putchar(nb + '0');
return (count);
}
int ft_putptr(uintptr_t ptr, const char format)
{
int count;
count = 0;
if (ptr >= 16)
{
count += ft_putptr(ptr / 16, format);
count += ft_putptr(ptr % 16, format);
}
else if (ptr < 10)
count += ft_putchar(ptr + '0');
else
count += ft_putchar(ptr + 'a' - 10);
return (count);
}