-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.c
76 lines (67 loc) · 1011 Bytes
/
utils.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "push_swap.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
if (n == 0)
return (0);
i = 0;
while (s1[i] == s2[i] && s1[i] != '\0')
{
if (i < (n - 1))
i++;
else
return (0);
}
return ((unsigned char)(s1[i]) - (unsigned char)(s2[i]));
}
int ft_atoi(const char *str)
{
int sign;
long long num;
sign = 1;
num = 0;
while ((*str == 32) || (*str >= 9 && *str <= 13))
str++;
if (*str == 45)
{
sign *= -1;
str++;
}
else if (*str == 43)
str++;
while (*str >= 48 && *str <= 57)
{
num = num * 10;
num += (sign * (*(str++) - '0'));
if (num > 2147483647)
return (-1);
if (num < -2147483648)
return (0);
}
return (num);
}
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
int ft_isdigit(int c)
{
if (c >= 48 && c <= 57)
return (1);
else
return (0);
}
void ft_bzero(void *str, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
((unsigned char *)str)[i] = '\0';
i++;
}
}