-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminitalk_utils_bonus.c
71 lines (63 loc) · 1.66 KB
/
minitalk_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minitalk_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yopi <yopi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/08 19:15:15 by yopi #+# #+# */
/* Updated: 2022/01/11 03:16:29 by yopi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_minitalk.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
int ft_str_isnum(char *str)
{
int i;
i = 0;
while (str[i] >= '0' && str[i] <= '9')
{
++i;
if (str[i] == '\0')
return (1);
}
return (0);
}
void ft_putnbr_fd(int n, int fd)
{
int long nbr;
nbr = (int long) n;
if (nbr < 0)
{
write(fd, "-", 1);
nbr *= -1;
}
if (n / 10)
ft_putnbr_fd(nbr / 10, fd);
ft_putchar_fd(nbr % 10 + '0', fd);
}
int ft_atoi(const char *str)
{
int j;
int res;
j = 1;
res = 0;
while (*str == '\t' || *str == '\f' || *str == '\r'
|| *str == ' ' || *str == '\v' || *str == '\n')
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
j *= -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
res = res * 10 + (*str - '0');
str++;
}
return (res * j);
}