-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
98 lines (88 loc) · 1.88 KB
/
Copy pathutils.c
File metadata and controls
98 lines (88 loc) · 1.88 KB
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
89
90
91
92
93
94
95
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtrinida <gtrinida@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 18:16:07 by gtrinida #+# #+# */
/* Updated: 2022/03/11 22:21:36 by gtrinida ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
void ft_putstr_fd_exit(char *s, int fd)
{
int i;
i = 0;
if (!s)
return ;
while (s[i] != '\0')
{
write(fd, &s[i], 1);
i++;
}
exit(1);
}
void ft_putstr_fd(char *s, int fd)
{
int i;
i = 0;
if (!s)
return ;
while (s[i] != '\0')
{
write(fd, &s[i], 1);
i++;
}
}
int ft_nlen(int n)
{
long long int number;
int count;
count = 0;
number = n;
if (number < 0)
{
number = number * (-1);
count++;
}
if (number == 0)
count++;
while (number > 0)
{
number = number / 10;
count++;
}
return (count);
}
void ft_putnbr_fd(int n, int fd)
{
int i;
int len;
char num[10000];
long long int number;
number = n;
i = 0;
len = ft_nlen(n);
num[len--] = '\0';
if (number < 0)
{
num[0] = '-';
number = number * (-1);
}
else if (number == 0)
num[0] = '0';
while (number > 0)
{
num[len--] = '0' + (number % 10);
number = number / 10;
}
while (num[i] != '\0')
{
write(fd, &num[i++], 1);
}
}