-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrimly.c
More file actions
71 lines (63 loc) · 1.79 KB
/
grimly.c
File metadata and controls
71 lines (63 loc) · 1.79 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* grimly.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmodise <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/04/28 23:25:32 by mmodise #+# #+# */
/* Updated: 2016/04/28 23:43:59 by mmodise ### ########.fr */
/* */
/* ************************************************************************** */
#include "grimly.h"
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
int ft_pow(int pow, int in_v)
{
int prod_v;
prod_v = 1;
while(pow > 0)
{
prod_v *= in_v;
pow--;
}
return(prod_v);
}
int ft_atoi(char *str)
{
int cnt_v1;
int cnt_v2;
int *cnv_v;
int st_len;
int num_v;
int sum_v;
int sum_v2;
cnt_v1 = 0;
st_len = ft_strlen(str);
cnv_v = malloc(st_len + 1);
sum_v = 0;
num_v = 0;
sum_v2 = 0;
while(str[cnt_v1])
{
cnv_v[cnt_v1] = str[cnt_v1] - '0';
cnt_v1++;
}
cnt_v2 = cnt_v1;
cnt_v1 = 0;
while(cnt_v1 <= cnt_v2 + 1)
{
sum_v = ft_pow(cnt_v2, 10) / 10;
num_v = sum_v * cnv_v[cnt_v1];
sum_v2 += num_v;
cnt_v1++;
cnt_v2--;
}
return(sum_v2);
}