projects
/
cProgLang
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
3d5a5a2
)
Added exercise 1-9
author
Cian Bagshaw
<cian@cianb.xyz>
Thu, 8 Dec 2022 11:41:25 +0000
(11:41 +0000)
committer
Cian Bagshaw
<cian@cianb.xyz>
Thu, 8 Dec 2022 11:41:25 +0000
(11:41 +0000)
1/9.c
[new file with mode: 0644]
patch
|
blob
diff --git a/1/9.c
b/1/9.c
new file mode 100644
(file)
index 0000000..
a930160
--- /dev/null
+++ b/
1/9.c
@@ -0,0
+1,18
@@
+/*
+ Exercise 1-9. Write a program to copy its input to its output, replacing each
+ string of one or more blanks by a single blank.
+ ===
+*/
+
+#include <stdio.h>
+
+int main () {
+ int c, w;
+
+ w=0; /* word: 0=space, 1=word */
+ while ((c=getchar())!=EOF) {
+ if (c!=' ' && !w) w=1; /* word begins */
+ if (w) putchar(c); /* print character */
+ if (c==' ' && w) w=0; /* word ends */
+ }
+}