aboutsummaryrefslogtreecommitdiff
path: root/c02/ex11
diff options
context:
space:
mode:
authorCabergs Charles <cacharle@e-r6-p7.s19.be>2019-07-04 21:56:50 +0200
committerCabergs Charles <cacharle@e-r6-p7.s19.be>2019-07-04 21:56:50 +0200
commitdbfa9d5d6b8bebde60f714253409ad46e328d358 (patch)
tree7f470d33293979e8c125302f0cf808a0b7df44f3 /c02/ex11
parent9675f63eac7a10d1814324067209935de71495cf (diff)
downloadpiscine-dbfa9d5d6b8bebde60f714253409ad46e328d358.tar.gz
piscine-dbfa9d5d6b8bebde60f714253409ad46e328d358.tar.bz2
piscine-dbfa9d5d6b8bebde60f714253409ad46e328d358.zip
c02 ex11 mindfuck solved, c02 test
Diffstat (limited to 'c02/ex11')
-rw-r--r--c02/ex11/ft_putstr_non_printable.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/c02/ex11/ft_putstr_non_printable.c b/c02/ex11/ft_putstr_non_printable.c
new file mode 100644
index 0000000..0171464
--- /dev/null
+++ b/c02/ex11/ft_putstr_non_printable.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_putstr_non_printable.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/04 16:46:03 by cacharle #+# #+# */
+/* Updated: 2019/07/04 21:53:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <unistd.h>
+
+void ft_putchar(char c)
+{
+ write(1, &c, 1);
+}
+
+void ft_putstr_non_printable(char *str)
+{
+ unsigned char tmp;
+ unsigned char *cursor;
+ char *hex_symbols;
+
+ hex_symbols = "0123456789abcdef";
+ cursor = str;
+ while (*cursor != '\0')
+ {
+ if (*cursor >= ' ' && *cursor <= '~')
+ write(1, cursor, 1);
+ else
+ {
+ ft_putchar('\\');
+ tmp = *cursor / 16;
+ ft_putchar(hex_symbols[tmp]);
+ tmp = *cursor % 16;
+ ft_putchar(hex_symbols[tmp]);
+ }
+ cursor++;
+ }
+}