-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_utils.c
More file actions
88 lines (79 loc) · 1.78 KB
/
ft_printf_utils.c
File metadata and controls
88 lines (79 loc) · 1.78 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: isbesli <isbesli@student.42kocaeli.com. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/17 18:04:48 by isbesli #+# #+# */
/* Updated: 2023/08/17 18:04:51 by isbesli ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(char c)
{
return (write(1, &c, 1));
}
int ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
int ft_putstr(char *s)
{
if (!s)
s = "(null)";
if (write(1, s, ft_strlen(s)) == -1)
return (-1);
return (ft_strlen(s));
}
int ft_putnbr(int nb)
{
long n;
int i;
int tmp;
i = 0;
n = nb;
if (nb < 0)
{
if (write(1, "-", 1) == -1)
return (-1);
n = -n;
i++;
}
if (n > 9)
{
tmp = ft_putnbr(n / 10);
if (tmp == -1)
return (-1);
i += tmp;
}
if (ft_putchar(n % 10 + 48) == -1)
return (-1);
return (++i);
}
int ft_putnbr_unsigned(unsigned int nb)
{
int i;
int tmp;
i = 0;
if (nb > 9)
{
tmp = ft_putnbr_unsigned(nb / 10);
if (tmp == -1)
return (-1);
i += tmp + 1;
if (ft_putnbr_unsigned(nb % 10) == -1)
return (-1);
}
else
{
if (ft_putchar(nb + 48) == -1)
return (-1);
i++;
}
return (i);
}