-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_bonus.c
73 lines (66 loc) · 1.59 KB
/
utils_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zbabahmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/10 17:02:11 by zbabahmi #+# #+# */
/* Updated: 2023/03/09 00:14:36 by zbabahmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk_bonus.h"
int ft_atoi(char *str)
{
int i;
int sign;
int result;
i = 0;
sign = 1;
result = 0;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-')
{
sign = -1;
i++;
}
else if (str[i] == '+')
i++;
while (str[i] != '\0' && str[i] >= '0' && str[i] <= '9')
{
result *= 10;
result += str[i] - '0';
i++;
}
return (result * sign);
}
void ft_putchar(int c)
{
write(1, &c, 1);
}
void ft_putnbr(int n)
{
if (n >= 0 && n <= 9)
{
ft_putchar(n + '0');
}
else if (n < 0)
{
write (1, "-", 1);
n *= -1;
}
else if (n >= 10)
{
ft_putnbr(n / 10);
ft_putnbr(n % 10);
}
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}