-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_txt.c
59 lines (50 loc) · 1.58 KB
/
write_txt.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* write_txt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: daniema3 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 16:25:42 by daniema3 #+# #+# */
/* Updated: 2024/10/01 17:06:37 by daniema3 ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int write_char(char ch)
{
return (write(1, &ch, 1));
}
int write_str(char *str)
{
int i;
i = 0;
if (str == NULL)
return (write(1, "(null)", 6));
while (str[i] != '\0')
i += write(1, &str[i], 1);
return (i);
}
int write_base(unsigned long nb, char *base)
{
int i;
i = 0;
if (nb == 0)
return (0);
i += write_base(nb / 16, base);
i += write(1, &base[nb % 16], 1);
return (i);
}
int write_hex(unsigned long nb, char *base)
{
int res;
res = write_base(nb, base);
if (res == 0)
return (write(1, "0", 1));
return (res);
}
int write_ptr(void *ptr, char *base)
{
if (ptr == NULL)
return (write(1, "(nil)", 5));
return (write(1, "0x", 2) + write_hex((long) ptr, base));
}