-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_itoa_base.c
More file actions
115 lines (106 loc) · 2.78 KB
/
ft_itoa_base.c
File metadata and controls
115 lines (106 loc) · 2.78 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ppanchen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/21 15:32:34 by ppanchen #+# #+# */
/* Updated: 2017/02/06 17:04:43 by ppanchen ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa_base_dw(long long n, int base)
{
int i;
char *str;
int is_neg;
unsigned long long ncpy;
int tmp;
i = 0;
is_neg = 0;
(n < 0) && (is_neg = 1);
ncpy = M(n);
str = (char *)malloc(50);
if (!str)
return (0);
while (ncpy >= (unsigned long long)base)
{
tmp = ncpy % base;
str[i++] = tmp >= 10 ? 'a' + tmp - 10 : tmp + '0';
ncpy /= base;
}
tmp = ncpy % base;
str[i] = tmp >= 10 ? 'a' + tmp - 10 : tmp + '0';
if (is_neg == 1 && base == 10)
str[++i] = '-';
str[i + 1] = 0;
return (ft_strrev(str));
}
char *ft_itoa_base_up(long long n, int base)
{
int i;
char *str;
int is_neg;
unsigned long long ncpy;
int tmp;
i = 0;
is_neg = 0;
(n < 0) && (is_neg = 1);
ncpy = M(n);
str = (char *)malloc(50);
if (!str)
return (0);
while (ncpy >= (unsigned long long)base)
{
tmp = ncpy % base;
str[i++] = tmp >= 10 ? 'A' + tmp - 10 : tmp + '0';
ncpy /= base;
}
tmp = ncpy % base;
str[i] = tmp >= 10 ? 'A' + tmp - 10 : tmp + '0';
if (is_neg == 1 && base == 10)
str[++i] = '-';
str[i + 1] = 0;
return (ft_strrev(str));
}
char *ft_itoa_base_udw(unsigned long long ncpy, int base)
{
int i;
char *str;
int tmp;
i = 0;
str = (char *)malloc(50);
if (!str)
return (0);
while (ncpy >= (unsigned long long)base)
{
tmp = ncpy % base;
str[i++] = tmp >= 10 ? 'a' + tmp - 10 : tmp + '0';
ncpy /= base;
}
tmp = ncpy % base;
str[i] = tmp >= 10 ? 'a' + tmp - 10 : tmp + '0';
str[i + 1] = 0;
return (ft_strrev(str));
}
char *ft_itoa_base_uup(unsigned long long ncpy, int base)
{
int i;
char *str;
int tmp;
i = 0;
str = (char *)malloc(50);
if (!str)
return (0);
while (ncpy >= (unsigned long long)base)
{
tmp = ncpy % base;
str[i++] = tmp >= 10 ? 'A' + tmp - 10 : tmp + '0';
ncpy /= base;
}
tmp = ncpy % base;
str[i] = tmp >= 10 ? 'A' + tmp - 10 : tmp + '0';
str[i + 1] = 0;
return (ft_strrev(str));
}