48 lines
1.4 KiB
C
48 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_putstr_non_printable.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/03/21 02:59:50 by tischmid #+# #+# */
|
|
/* Updated: 2023/03/24 01:04:50 by tischmid ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <unistd.h>
|
|
#define HEX_ALPH "0123456789abcdef"
|
|
|
|
void ft_putstr_non_printable(char *str)
|
|
{
|
|
while (*str)
|
|
{
|
|
if (*str < 32)
|
|
{
|
|
write(1, "\\", 1);
|
|
write(1, &HEX_ALPH[*(unsigned char *) str / 16], 1);
|
|
write(1, &HEX_ALPH[*(unsigned char *) str % 16], 1);
|
|
}
|
|
else
|
|
write(1, str, 1);
|
|
++str;
|
|
}
|
|
}
|
|
|
|
/* ////
|
|
#include <stdio.h>
|
|
#define BUFSIZE 256
|
|
|
|
int main(void)
|
|
{
|
|
char s1[BUFSIZE];
|
|
|
|
for (int i = -128; i < 127; ++i)
|
|
{
|
|
s1[i + 128] = i ? i : 1;
|
|
}
|
|
ft_putstr_non_printable(s1);
|
|
return (0);
|
|
}
|
|
*/ ////
|