-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
60 lines (54 loc) · 1.39 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abkssiba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/04 12:42:37 by abkssiba #+# #+# */
/* Updated: 2019/12/13 17:09:14 by abkssiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
return (i);
}
char *to_hexa_uint(uintmax_t nb)
{
char *res;
int i;
uintmax_t j;
i = (nb == 0) ? 1 : 0;
j = nb;
while (j)
{
j /= 16;
i++;
}
res = (char *)malloc(i + 1);
res[i--] = '\0';
while (i >= 0)
{
j = nb % 16;
if (j >= 10)
res[i] = j - 10 + 'a';
else
res[i] = j + '0';
nb /= 16;
i--;
}
return (res);
}