From a8ca4de90f2c1d278b16ace6faf30fafa71128a0 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Thu, 11 Nov 2021 23:04:06 -0500 Subject: [PATCH] Exercise 1-9. Replace multiple blanks with one --- 07-extra-blanks.c | 16 ++++++++++++++++ Makefile | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 07-extra-blanks.c diff --git a/07-extra-blanks.c b/07-extra-blanks.c new file mode 100644 index 0000000..e875e6d --- /dev/null +++ b/07-extra-blanks.c @@ -0,0 +1,16 @@ +#include + +int main() +{ + int c; + int l; + + while ((c = getchar()) != EOF) { + if (c == ' ' && c == l) { + ; + } else { + printf("%c", c); + l = c; + } + } +} diff --git a/Makefile b/Makefile index 7e067df..babb6b7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: hello mathvars c2f input count countlines +all: hello mathvars c2f input count countlines blanks hello: 01-hello-world.c gcc -o ./bin/01-helloworld 01-hello-world.c @@ -18,5 +18,8 @@ count: 05-char-counting.c countlines: 06-line-count.c gcc -o ./bin/06-line-count 06-line-count.c +blanks: 07-extra-blanks.c + gcc -o ./bin/07-extra-blanks 07-extra-blanks.c + clean: $(RM) ./bin/*-*