From 47e036716113d11f8e978ca61edeef8326f25d50 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sun, 21 Apr 2024 17:03:21 +0400 Subject: [PATCH] 1.11 --- The C Programming Language/1.11.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 The C Programming Language/1.11.c diff --git a/The C Programming Language/1.11.c b/The C Programming Language/1.11.c new file mode 100644 index 0000000..1496781 --- /dev/null +++ b/The C Programming Language/1.11.c @@ -0,0 +1,26 @@ +#include + +#define IN 1 +#define OUT 0 + +main() +{ + int c, nl, nw, nc, state; + nl = nw = nc = 0; + while ((c = getchar()) != EOF) + { + ++nc; + // We do not handle \b, so words count get messed up if we erase anything + if (c == '\n') + ++nl; + if (c == ' ' || c == '\n' || c == '\t') + state = OUT; + else if (state == OUT) + { + state = IN; + ++nw; + } + } + printf("%d %d %d\n", nl, nw, nc); +} +