-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi_base.c
42 lines (39 loc) · 1.26 KB
/
ft_atoi_base.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chrhuang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 10:40:13 by chrhuang #+# #+# */
/* Updated: 2018/11/21 13:10:22 by chrhuang ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi_base(char *nb, char *base)
{
int i;
int j;
int res;
int len;
if (nb == NULL || base == NULL)
return (-1);
i = 0;
res = 0;
len = ft_strlen(base);
while (nb[i] != '\0')
{
j = 0;
while (base[j] != '\0')
{
if (base[j] == nb[i])
break ;
j = j + 1;
}
res = res + j;
if (nb[i + 1] != '\0')
res = res * len;
i = i + 1;
}
return (res);
}