aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2013-02-13 20:43:28 -0600
committerzlg <zlg@zlg.space>2013-02-13 20:43:28 -0600
commitb30a821e7b8e646d2d041f83611fc40cccfe032f (patch)
treec97e31990681f2770dc0a6a5ca16a7c73815b9a0
parentFix Exercise 1-12's solution (diff)
downloadknr-b30a821e7b8e646d2d041f83611fc40cccfe032f.tar.gz
knr-b30a821e7b8e646d2d041f83611fc40cccfe032f.tar.bz2
knr-b30a821e7b8e646d2d041f83611fc40cccfe032f.tar.xz
knr-b30a821e7b8e646d2d041f83611fc40cccfe032f.zip
Fix 1-09's solution
My initial solution tried to simplify the conditions for outputting a space. You really do need two 'if's in there.
-rw-r--r--1-09_single-spacing.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/1-09_single-spacing.c b/1-09_single-spacing.c
index 82447ee..4bf802a 100644
--- a/1-09_single-spacing.c
+++ b/1-09_single-spacing.c
@@ -15,8 +15,10 @@ int main(void) {
int spaces = 0;
while ((c = getchar()) != EOF) {
- if (c == ' ' && spaces == 0) {
- putchar(c);
+ if (c == ' ') {
+ if (spaces == 0) {
+ putchar(c);
+ }
spaces++;
} else {
putchar(c);