-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putstr_non_printable.c
41 lines (37 loc) · 1.26 KB
/
ft_putstr_non_printable.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_non_printable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbin-jef <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 07:36:16 by sbin-jef #+# #+# */
/* Updated: 2024/05/09 18:34:28 by sbin-jef ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int check(char x)
{
return (x >= 32 && x <= 126);
}
void ft_putstr_non_printable(char *str)
{
char v;
char hex[3];
while (*str)
{
v = *str;
if (check(v))
{
write(1, &v, 1);
}
else
{
hex[0] = '\\';
hex[1] = "0123456789abcdef"[(unsigned char)v >> 4];
hex[2] = "0123456789abcdef"[(unsigned char)v & 0x0F];
write(1, hex, 3);
}
str++;
}
}