-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
65 lines (58 loc) · 1.43 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asodor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/05 04:41:52 by asodor #+# #+# */
/* Updated: 2024/05/05 06:15:58 by asodor ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}
int ft_putstr(char *s)
{
int i;
i = 0;
if (s == NULL)
{
write(1, "(null)", 6);
return (6);
}
while (s[i])
ft_putchar(s[i++]);
return (i);
}
void ft_putnbr(long n)
{
if (n < 0)
{
ft_putchar('-');
n = -n;
}
if (n >= 10)
{
ft_putnbr(n / 10);
ft_putnbr(n % 10);
}
if (n < 10)
ft_putchar(n + 48);
}
long ft_mini_atoi(char *s)
{
int i;
long r;
i = 0;
r = 0;
while (s[i] && (s[i] >= '0' && s[i] <= '9'))
{
r = r * 10;
r = r + s[i] - '0';
i++;
}
return (r);
}