-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils.c
79 lines (70 loc) · 1.68 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: rrakman <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/07 23:18:17 by rrakman #+# #+# */
/* Updated: 2022/12/06 20:06:44 by rrakman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i])
i++;
return (i);
}
int ft_putstr(char *s)
{
if (s == NULL)
{
ft_putstr("(null)");
return (6);
}
write(1, s, ft_strlen(s));
return (ft_strlen(s));
}
int ft_putnbr(int n)
{
long num;
int count;
count = 0;
num = n;
if (num < 0)
{
count += ft_putchar('-');
num *= -1;
}
if (num < 10)
count += ft_putchar(num + '0');
else
{
count += ft_putnbr(num / 10);
count += ft_putnbr(num % 10);
}
return (count);
}
int ft_putunsigned(unsigned int n)
{
long num;
int count;
count = 0;
num = n;
if (num < 10)
count += ft_putchar(num + '0');
else
{
count += ft_putunsigned(num / 10);
count += ft_putunsigned(num % 10);
}
return (count);
}