-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_functions.c
103 lines (93 loc) · 1.87 KB
/
ft_functions.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahaifoul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/20 18:29:23 by ahaifoul #+# #+# */
/* Updated: 2021/11/23 12:10:54 by ahaifoul ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putstr(char *str)
{
int i;
i = 0;
if (!str)
{
write(1, "(null)", 6);
return (6);
}
while (str[i])
{
write (1, &str[i], 1);
i++;
}
return (i);
}
int ft_putchar(char c)
{
write (1, &c, 1);
return (1);
}
int str_len(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int base_convert_x(long int nb)
{
int j;
int tab[100];
int i;
char *base;
base = "0123456789abcdef";
i = 0;
j = 0;
if (nb == 0)
i += ft_putchar(base[0]);
if (nb < 0)
{
tab[0] = '-';
j++;
nb = -nb;
}
while (nb)
{
tab[j++] = nb % 16;
nb = nb / 16;
}
while (--j >= 0)
i += ft_putchar(base[tab[j]]);
return (i);
}
int base_convert_up(long int nb)
{
int j;
int tab[100];
int i;
char *base;
base = "0123456789ABCDEF";
i = 0;
j = 0;
if (nb == 0)
i += ft_putchar(base[0]);
if (nb < 0)
{
tab[0] = '-';
j++;
nb = -nb;
}
while (nb)
{
tab[j++] = nb % 16;
nb = nb / 16;
}
while (--j >= 0)
i += ft_putchar(base[tab[j]]);
return (i);
}