-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
64 lines (56 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkiragu <jkiragu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/03 15:13:26 by jkiragu #+# #+# */
/* Updated: 2022/11/07 11:53:44 by jkiragu ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int n)
{
if (n > 9)
ft_putnbr(n / 10);
write(1, &"0123456789"[n % 10], 1);
}
void ft_putstr(char *str)
{
while (*str)
write(1, str++, 1);
}
int ft_atoi(const char *str)
{
int num;
int sign;
sign = 1;
num = 0;
while (*str >= 7 && *str <= 14)
str++;
if (*str == '-')
sign = -1;
if (*str == '-' || *str == '+')
str++;
while (*str >= '0' && *str <= '9')
{
num = num * 10 + (*str - 48);
str++;
}
return (num * sign);
}
size_t ft_strlen(const char *str)
{
int i;
if (!str)
return (0);
i = 0;
while (str[i])
i++;
return (i);
}