-
Notifications
You must be signed in to change notification settings - Fork 0
/
lil_libft.c
63 lines (57 loc) · 1.52 KB
/
lil_libft.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lil_libft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 14:58:36 by zwalad #+# #+# */
/* Updated: 2022/03/23 15:58:10 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
size_t ps_strlen(char *s)
{
int i;
i = 0;
while (s[i])
{
i++;
}
return (i);
}
int ps_isdigit(char c)
{
if ((c >= '0' && c <= '9') || c == '\0')
{
return (1);
}
return (0);
}
int ps_atoi(char *str)
{
int i;
int j;
long n;
long c;
i = 0;
j = 1;
n = 0;
while (str[i] == ' ' || (9 <= str[i] && str[i] <= 13))
i++;
if (str[i] == '-')
j = -1;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
n = (n * 10) + str[i] - '0';
i++;
}
if (!ps_isdigit(str[i]) || str[0] == '\0')
herror(1);
c = j * n;
if ((c > 2147483647) || (c < -2147483648))
herror(1);
return (c);
}