-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.c
78 lines (69 loc) · 1.76 KB
/
utilities.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* utilities.c :+: :+: */
/* +:+ */
/* By: rcappend <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/12/11 12:48:48 by rcappend #+# #+# */
/* Updated: 2020/12/11 15:50:12 by rcappend ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int counter(unsigned long long n)
{
int i;
i = 1;
while (n / 16 != 0)
{
i++;
n = n / 16;
}
return (i);
}
char *ft_itoa_ptr(unsigned long long n)
{
char *ret;
int len;
char *base;
base = "0123456789abcdef";
len = counter(n) + 2;
ret = malloc(sizeof(unsigned char) * len + 1);
if (!ret)
return (NULL);
ret[0] = '0';
ret[1] = 'x';
ret[len] = '\0';
while (len > 2)
{
len--;
ret[len] = base[n % 16];
n = n / 16;
}
return (ret);
}
int value_output_combiner(char **output, t_track *c, size_t *len)
{
char *temp;
temp = ft_strjoin(*output, c->value);
if (!temp)
{
free(c->value);
return (EXIT_FAILURE);
}
*len += ft_strlen(c->value);
free(*output);
free(c->value);
*output = temp;
return (EXIT_SUCCESS);
}
void print_string(char *output, size_t len)
{
size_t i;
i = 0;
while (i < len)
{
write(1, &output[i], 1);
i++;
}
}