Repository navigation
Expand file tree
/
Copy pathsub_printf.c
More file actions
88 lines (78 loc) · 1.7 KB
/
Copy pathsub_printf.c
File metadata and controls
88 lines (78 loc) · 1.7 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sub_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mrafik <mrafik@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/03 23:11:07 by mrafik #+# #+# */
/* Updated: 2021/12/07 22:50:47 by mrafik ### ########.fr */
/* */
/* ************************************************************************** */
#include"ft_printf.h"
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_putnbr(int nb)
{
unsigned int nbr;
int i;
i = 0;
nbr = nb;
if (nb < 0)
{
nbr = nb * (-1);
i += ft_putchar('-');
}
if (nbr >= 10)
{
i += ft_putnbr(nbr / 10);
}
i += ft_putchar(nbr % 10 + '0');
return (i);
}
int ft_putstr(char *s)
{
int i;
i = 0;
if (!s)
{
write(1, "(null)", 6);
i = 6;
}
else
{
while (s[i])
{
write(1, &s[i], 1);
i++;
}
}
return (i);
}
int ft_hexa(unsigned int nb, char *base, unsigned int b)
{
int c;
c = 0;
if (nb >= b)
{
c += ft_hexa(nb / b, base, b);
}
c += ft_putchar(base[nb % b]);
return (c);
}
int ft_p(unsigned long long nb)
{
int c;
char *base;
base = "0123456789abcdef";
c = 0;
if (nb >= 16)
{
c += ft_p(nb / 16);
}
c += ft_putchar(base[nb % 16]);
return (c);
}