-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_2.c
85 lines (76 loc) · 1.1 KB
/
utils_2.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
#include "printf.h"
void reverse_str(char **res, char *str, int len)
{
int i;
if (!(*res = ft_strdup(str)))
return ;
i = 0;
while (len)
{
(*res)[i] = str[len - 1];
i++;
len--;
}
}
char *ft_itoa_16(unsigned int value, int big_letters)
{
int i;
int mod;
char str[256];
char *res;
i = 0;
*str = '0';
str[1] = '\0';
while (value)
{
mod = value % 16;
if (mod < 10)
str[i] = '0' + mod;
else
str[i] = mod - 10 + (big_letters ? 'A' : 'a');
value /= 16;
i++;
}
str[*str == '0' && ft_strlen(str) == 1 ? 1 : i] = '\0';
reverse_str(&res, str, i);
return (res);
}
int is_type(char c)
{
char *types;
types = "%cspdiuxX";
while (*types)
{
if (c == *types)
return (1);
types++;
}
return (0);
}
int pos_or_zero(int num)
{
if (num >= 0)
return (num);
return (0);
}
char *ft_itoa_for_p(unsigned long long value)
{
int i;
int mod;
char str[256];
char *res;
i = 0;
while (value)
{
mod = value % 16;
if (mod < 10)
str[i] = '0' + mod;
else
str[i] = mod - 10 + 'a';
value /= 16;
i++;
}
str[i] = '\0';
reverse_str(&res, str, i);
return (res);
}