-
Notifications
You must be signed in to change notification settings - Fork 0
/
nketa.c
106 lines (97 loc) · 2.45 KB
/
nketa.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
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* nketa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kaoyama <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/08 18:42:47 by kaoyama #+# #+# */
/* Updated: 2022/05/08 18:52:28 by kaoyama ### ########.fr */
/* */
/* ************************************************************************** */
#include "declaration.h"
char *billion(unsigned int n, char *ans, t_dict dict[])
{
unsigned int i;
unsigned int mod;
char *p;
if (n > 999999999)
{
mod = n % ft_power(10, 9);
n = n / ft_power(10, 9);
p = miketa(n, ans, dict);
i = 0;
while (dict[i].value != '\0')
{
if (dict[i].key == ft_power(10, 9) && n != 0)
{
return (ft_strcat_space(p, dict[i].value));
}
i++;
}
n = mod;
}
return (ans);
}
char *million(unsigned int n, char *ans, t_dict dict[])
{
unsigned int i;
unsigned int mod;
char *p;
if (n > 999999)
{
mod = n % ft_power(10, 6);
n = n / ft_power(10, 6);
p = miketa(n, ans, dict);
i = 0;
while (dict[i].value != '\0')
{
if (dict[i].key == ft_power(10, 6) && n % 1000)
{
return (ft_strcat_space(p, dict[i].value));
}
i++;
}
n = mod;
}
return (ans);
}
char *thousand(unsigned int n, char *ans, t_dict dict[])
{
unsigned int i;
unsigned int mod;
char *p;
if (n > 999)
{
mod = n % ft_power(10, 3);
n = n / ft_power(10, 3);
p = miketa(n, ans, dict);
i = 0;
while (dict[i].value != '\0')
{
if (dict[i].key == ft_power(10, 3) && n % 1000)
{
return (ft_strcat_space(p, dict[i].value));
}
i++;
}
n = mod;
}
return (ans);
}
void nketa(unsigned int n, t_dict dict[])
{
char *ans;
char *p1;
char *p2;
char *p3;
unsigned int mod;
ans = (char *)malloc(sizeof(char) * 2048);
mod = n % ft_power(10, 3);
ifzero(n, ans, dict);
p1 = billion(n, ans, dict);
p2 = million(n, p1, dict);
p3 = thousand(n, p2, dict);
miketa(mod, p3, dict);
display(ft_delete_lastspace(ans));
}