From: Cian Bagshaw Date: Thu, 8 Dec 2022 15:03:07 +0000 (+0000) Subject: Added exercise 1-10 X-Git-Url: https://tests.cianb.xyz/?a=commitdiff_plain;h=2104e281a7e3f0cc9a6eb12f1f3bbe1198cb9445;p=cProgLang Added exercise 1-10 --- 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 */ + } +}