35 "",
"sto ",
"dwieście ",
"trzysta ",
"czterysta ",
"pięćset ",
36 "sześćset ",
"siedemset ",
"osiemset ",
"dziewięćset "};
39 "dziesięć ",
"jedenaście ",
"dwanaście ",
"trzynaście ",
40 "czternaście ",
"piętnaście ",
"szesnaście ",
"siedemnaście ",
41 "osiemnaście ",
"dziewiętnaście "};
44 "",
"",
"dwadzieścia ",
"trzydzieści ",
"czterdzieści ",
45 "pięćdziesiąt ",
"sześćdziesiąt ",
"siedemdziesiąt ",
46 "osiemdziesiąt ",
"dziewięćdziesiąt "};
49 "",
"jeden ",
"dwa ",
"trzy ",
"cztery ",
"pięć ",
50 "sześć ",
"siedem ",
"osiem ",
"dziewięć "};
53 {
"złoty ",
"złote ",
"złotych "},
54 {
"tysiąc ",
"tysiące ",
"tysięcy "},
55 {
"milion ",
"miliony ",
"milionów "},
56 {
"miliard ",
"miliardy ",
"miliardów "},
57 {
"bilion ",
"biliony ",
"bilionów "},
58 {
"biliard",
"biliardy",
"biliardów"},
59 {
"trylion",
"tryliony",
"trylionów"},
60 {
"tryliard",
"tryliardy",
"tryliardów"},
61 {
"kwadrylion",
"kwadryliony",
"kwadrylionów"},
62 {
"kwintylion",
"kwintyliony",
"kwintylionów"},
63 {
"sekstylion",
"sekstyliony",
"sekstylionów"}};
100 static uint64_t power (uint64_t x,
101 int n) __attribute__ ((
const));
103 static uint8_t get_digit (uint64_t x,
104 uint8_t pos) __attribute__ ((
const));
106 static void divide_split (uint64_t *x,
109 static void check_resize (
char **buff,
110 const size_t ui_len);
112 static int prestr (uint8_t n,
125 return x * power (x, n - 1);
132 get_digit (uint64_t x,
135 return (uint8_t) ((x - x / power (10, pos + 1) * power (10, pos + 1)) /
143 divide_split (uint64_t *x,
146 y[2] = get_digit (*x, 0);
147 y[1] = get_digit (*x, 1);
148 y[0] = get_digit (*x, 2);
157 check_resize (
char **buff,
161 *buff = malloc (ui_len *
sizeof (
char));
164 *buff = realloc (*buff, ui_len *
sizeof (
char));
167 puts (
"Error (re)allocating memory");
176 prestr (uint8_t n, ...)
186 dst = va_arg (vl,
char**);
187 for (i = 1; i < n; ++i) {
188 src = va_arg (vl,
char*);
189 ui_srl = strlen (src);
190 ui_dsl = strlen (*dst);
191 check_resize (dst, ui_srl + ui_dsl + 1);
192 memmove ((*dst) + ui_srl, *dst, ui_dsl + 1);
193 memmove (*dst, src, ui_srl);
207 d_val = d_price * 100.0;
208 d_val = round (d_val);
220 char *s_price = NULL;
221 uint64_t ui_price = 0;
223 uint64_t ui_prtmp = 0;
224 uint8_t ui_prlen = 0;
225 uint8_t p [3] = {0, 0, 0};
228 ui_price = ui_inprice / 100;
230 ui_gr = ui_inprice - (ui_inprice / 100 * 100);
232 while (ui_prtmp || ui_prlen % 3) {
236 check_resize (&s_price, 10);
237 sprintf (s_price,
"%" PRIu64
"/100", ui_gr);
238 for (i = 0; i < ui_prlen / 3; ++i) {
239 divide_split (&ui_price, p);
240 if (p[1] == 1) prestr (3, &s_price, ends[i][2], teens[p[2]]);
244 prestr (2, &s_price, ends[i][2]);
245 if (p[0] == 0 && p[1] == 0 && ui_prlen == 3)
246 prestr (2, &s_price,
"zero ");
248 else if (! (p[0] == 0 && p[1] == 0 && ui_prlen > ((i + 1) * 3)))
249 prestr (2, &s_price, ends[i][2]);
251 else if (p[2] == 1) {
252 if (p[0] == 0 && p[1] == 0)
253 prestr (3, &s_price, ends[i][0], ones[p[2]]);
254 else prestr (3, &s_price, ends[i][2], ones[p[2]]);
256 else if (p[2] > 1 && p[2] < 5)
257 prestr (3, &s_price, ends[i][1], ones[p[2]]);
258 else prestr (3, &s_price, ends[i][2], ones[p[2]]);
259 prestr (2, &s_price, tens[p[1]]);
261 prestr (2, &s_price, hundreds[p[0]]);