/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr_non_printable.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: whaffman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/06 18:24:39 by whaffman #+# #+# */ /* Updated: 2024/06/10 12:06:13 by whaffman ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include void ft_putchar(char c) { write(1, &c, 1); } void ft_puthex(int c) { if (c < 10) ft_putchar(c + '0'); else if (c > 9 && c < 16) { ft_putchar(c - 10 + 'a'); } } void ft_putstr_non_printable(char *str) { while (*str != '\0') { if (*str >= 32 && *str <= 126) write(1, str, 1); else { ft_putchar('\\'); ft_puthex(*str / 16); ft_puthex(*str % 16); } str++; } } #ifdef DEBUG int main(void) { char str[15]; int i; strcpy(&str[0], "Hello, \n World!"); ft_putstr_non_printable(str); printf("\n"); i = 0; while (i <= 127) { strcpy(&str[0], (char [2]){(char) i, '\0'}); ft_putstr_non_printable(str); i++; } return (0); } #endif