Repository navigation
Expand file tree
/
Copy pathutils.c
More file actions
105 lines (94 loc) · 1.89 KB
/
Copy pathutils.c
File metadata and controls
105 lines (94 loc) · 1.89 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aasselma <aasselma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/12 00:18:22 by aasselma #+# #+# */
/* Updated: 2023/04/27 17:40:00 by aasselma ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
long ft_atoi(char *s)
{
long r;
long sign;
long i;
int z;
z = 0;
r = 0;
sign = 1;
i = 0;
while (s[i] == '0')
i++;
if (s[i] == '-' || s[i] == '+')
{
if (s[i] == '-')
sign = -1;
i++;
}
while (s[i] >= '0' && s[i] <= '9')
{
r = r * 10 + s[i++] - '0';
z++;
}
if (z > 11)
ft_exit();
return (r * sign);
}
int ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
int ft_cal_len(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
if (str[i + 1] == ' ' || str[i + 1] == '\0')
return (i);
}
return (0);
}
void ft_cal_str(char *str, t_stack *stored_a)
{
int i;
i = 0;
while (str[i] != '\0')
{
if ((str[i] >= '0' && str[i] <= '9'))
{
if (str[i + 1] == ' ' || str[i + 1] == '\0')
stored_a->len++;
}
i++;
}
}
int get_max_num(int *stored, int len)
{
int j;
int max;
int index;
index = 0;
j = 0;
max = 0;
while (j != len)
{
if (max < stored[j])
{
max = stored[j];
index = j;
}
j++;
}
return (index);
}