From 2104e281a7e3f0cc9a6eb12f1f3bbe1198cb9445 Mon Sep 17 00:00:00 2001 From: Cian Bagshaw Date: Thu, 8 Dec 2022 15:03:07 +0000 Subject: [PATCH] Added exercise 1-10 --- 1/10.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 1/10.c diff --git a/1/10.c b/1/10.c new file mode 100644 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 + +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 */ + } +} -- 2.20.1