From d8a70f8b58ab634edcf60cbb7e3bcb9a55b1564e Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Thu, 11 Nov 2021 23:30:43 -0500 Subject: [PATCH] Exercise 1-10. replace with escape codes --- 08-unambiguous.c | 17 +++++++++++++++++ Makefile | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 08-unambiguous.c diff --git a/08-unambiguous.c b/08-unambiguous.c new file mode 100644 index 0000000..11ddfff --- /dev/null +++ b/08-unambiguous.c @@ -0,0 +1,17 @@ +#include + +int main() +{ + int c; + + while ((c = getchar()) != EOF) { + if (c == '\t') + printf("\\t"); + else if (c == '\b') + printf("\\b"); + else if (c == '\\') + printf("\\\\"); + else + printf("%c", c); + } +} diff --git a/Makefile b/Makefile index babb6b7..f34ca9c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: hello mathvars c2f input count countlines blanks +all: hello mathvars c2f input count countlines blanks unambiguous hello: 01-hello-world.c gcc -o ./bin/01-helloworld 01-hello-world.c @@ -21,5 +21,8 @@ countlines: 06-line-count.c blanks: 07-extra-blanks.c gcc -o ./bin/07-extra-blanks 07-extra-blanks.c +unambiguous: 08-unambiguous.c + gcc -o ./bin/08-unambiguous 08-unambiguous.c + clean: $(RM) ./bin/*-*