Added exercise 1-10
authorCian Bagshaw <cian@cianb.xyz>
Thu, 8 Dec 2022 15:03:07 +0000 (15:03 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Thu, 8 Dec 2022 15:03:07 +0000 (15:03 +0000)
1/10.c [new file with mode: 0644]

diff --git a/1/10.c b/1/10.c
new file mode 100644 (file)
index 0000000..0b2d0ae
--- /dev/null
+++ b/1/10.c
@@ -0,0 +1,19 @@
+/*
+       Exercise 1-10. Write a program to copy its input to its output, replacing each
+       tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and
+       backspaces visible in an unambiguous way.
+       ===
+*/
+
+#include <stdio.h>
+
+int main () {
+       int c;
+
+       while ((c=getchar())!=EOF) {
+               if (c=='\t') { printf("\\t");   continue; }     /* tab */
+               if (c=='\b') { printf("\\b");   continue; }     /* backspace */
+               if (c=='\\') { printf("\\\\");  continue; }     /* backslash */
+               putchar(c);     /* other */
+       }
+}