summaryrefslogtreecommitdiffstats
path: root/1
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-17 21:18:17 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-17 21:18:17 +0800
commit3a73a8409249dd30785c96c155377774648dd71e (patch)
tree50af7e7740c5810f629b82234b45ab9214fb425c /1
parent49a03e32c1f419e98c8886d46c438b3efa859947 (diff)
downloadk&r-exercises-3a73a8409249dd30785c96c155377774648dd71e.tar.gz
1.9
Diffstat (limited to '1')
-rw-r--r--1/9.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/1/9.c b/1/9.c
new file mode 100644
index 0000000..2fb4866
--- /dev/null
+++ b/1/9.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+/* replaces one or more blanks with a single blank */
+int main(int argc, char *argv[]) {
+ int prev, curr;
+
+ prev = 'a';
+
+ while ((curr = getchar()) != EOF) {
+ if (prev == ' ' && curr == ' ') {
+ continue;
+ }
+
+ putchar(curr);
+ prev = curr;
+ }
+
+ return 0;
+} \ No newline at end of file