-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_utils.c
72 lines (64 loc) · 1.61 KB
/
client_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anaouadi <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 12:40:37 by anaouadi #+# #+# */
/* Updated: 2022/03/10 14:39:18 by anaouadi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int get_bit(unsigned char num, int k)
{
return (num & (1 << k));
}
int ft_start(const char *s)
{
int i;
i = 0;
while (s[i] == '\t' || s[i] == '\n' || s[i] == '\r'
|| s[i] == '\v' || s[i] == '\f' || s[i] == ' ')
{
i++;
}
return (i);
}
int ft_atoi(const char *nptr)
{
int len;
int i;
int sign;
int rslt;
len = ft_strlen(nptr);
i = ft_start(nptr);
rslt = 0;
sign = 1;
if (nptr[i] == '-')
{
i++;
sign = -1;
}
else if (nptr[i] == '+')
i++;
while (i < len)
{
if (nptr[i] >= '0' && nptr[i] <= '9')
rslt = nptr[i] + rslt * 10 - 48;
else
break ;
i++;
}
return (sign * rslt);
}
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
if (!s)
return (0);
while (s[i])
i++;
return (i);
}