blob: b595a5c905adda964f653444cf49a1459737a7c4 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/06 08:07:17 by cacharle #+# #+# */
/* Updated: 2019/07/06 08:30:16 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
int my_pow(int base, int exponent)
{
int accumulator;
accumulator = 1;
while (exponent > 0)
{
accumulator *= base;
exponent--;
}
return (accumulator);
}
int ft_atoi_base(char *str, char *base)
{
int radix;
int i;
int j;
int nb;
radix = 0;
while (base[radix])
radix++;
i = 0;
while (str[i])
i++;
j = 0;
while (i > 0)
{
nb += my_pow(radix, j);
nb %= radix;
i--;
j++;
}
return nb;
}
|