-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_tools.c
64 lines (55 loc) · 1.57 KB
/
ft_printf_tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elel-yak <elel-yak@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 18:22:49 by elel-yak #+# #+# */
/* Updated: 2022/12/23 20:34:38 by elel-yak ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(char c)
{
return (write(1, &c, 1));
}
int ft_putstr(char *str)
{
if (!str)
return (write(1, "(null)", 6));
return (write(1, str, ft_strlen(str)));
}
int ft_putnbr_base(unsigned long nb, char *base)
{
int count;
count = 0;
if (nb >= 16)
count += ft_putnbr_base(nb / 16, base);
count += ft_putchar(base[nb % 16]);
return (count);
}
int ft_putnbr(long n)
{
int count;
count = 0;
if (n < 0)
{
n *= -1;
count += write(1, "-", 1);
}
if (n > 9)
count += ft_putnbr(n / 10);
count += ft_putchar((n % 10) + 48);
return (count);
}
size_t ft_strlen(char *str)
{
int count;
count = 0;
if (!str)
return (0);
while (str[count])
count++;
return (count);
}