#include <stdio.h>

void print(char c)
{
	printf("%c", c);
}

void  translate(int c, char *o)
{
	int r;
	o[0] = c / 16 + '0';
	r = c % 16;

	if (r < 10)
		o[1] = r + '0';
	else
		o[1] = r - 10 + 'a';
	o[2] = '\0';
}

void ft_putstr_non_printable(char* str)
{
	int i;
	char o[3];

	i = 0;
	while (str[i] != '\0')
	{
		if (str[i] >= 32 && str[i] <= 126)
		{
			print(str[i]);
		}
		else
		{
			translate((unsigned char)str[i], o);
			print('\\');
			print(o[0]);
			print(o[1]);
		}
		i++;
	}
}

int main(void)
{
	char    str1[99] = "Coucou\n\ntu vas bien ?";
	char	str2[99] = "moi aussi je vais très bien";
	ft_putstr_non_printable(str1);
	printf("\n");
	//printf("%s\n", "Coucou\0atu vas bien ?");
	//ft_putstr_non_printable(str2);
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: