-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.c
88 lines (79 loc) · 1.73 KB
/
tools.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
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybourais <ybourais@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 15:47:54 by ybourais #+# #+# */
/* Updated: 2023/01/06 17:43:09 by ybourais ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int ft_strlen(char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
int ft_atoi(char *str)
{
int i;
int res;
int sign;
i = 0;
res = 0;
sign = 1;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
i++;
if (str[i] == 45)
{
sign = sign * (-1);
i++;
}
else if (str[i] == 43)
i++;
while (str[i] >= 48 && str[i] <= 57)
{
res = res * 10 + str[i] - 48;
i++;
}
return (res * sign);
}
void ft_putstr(char *s)
{
size_t i;
size_t l;
if (!s)
return ;
l = ft_strlen(s);
i = 0;
while (i < l)
{
write(1, &s[i], sizeof(s[i]));
i++;
}
}
void ft_putchar(char c)
{
write(1, &c, sizeof(c));
}
void ft_putnbr(int n)
{
if (n < 0)
{
n = n * -1;
ft_putchar('-');
}
if (n >= 0 && n < 10)
{
ft_putchar(n + '0');
}
else if (n >= 10)
{
ft_putnbr(n / 10);
ft_putchar((n % 10) + '0');
}
}