-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_utils.c
61 lines (55 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cproesch <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/04 18:20:12 by cproesch #+# #+# */
/* Updated: 2021/08/04 18:20:18 by cproesch ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_strlen(const char *s)
{
int n;
n = 0;
while (s[n])
n++;
return (n);
}
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *s)
{
if (s)
write(1, s, ft_strlen(s));
}
void ft_putnbr(int n, int *j)
{
if (n == -2147483648)
{
ft_putstr("-2147483648");
(*j) = (*j) + 11;
}
else if (n < 0)
{
ft_putchar('-');
(*j)++;
n = -n;
ft_putnbr(n, j);
}
else if (n > 9)
{
ft_putnbr((n / 10), j);
ft_putchar((n % 10) + 48);
(*j)++;
}
else
{
ft_putchar(n + 48);
(*j)++;
}
}