From 2523043172a8816ffd88562b5476e9077bbe0b18 Mon Sep 17 00:00:00 2001 From: Reina Harrington-Affine Date: Sat, 16 Aug 2025 02:07:42 +0000 Subject: [PATCH] Nearly direct copy of a word count program from KNR C, mimicked here only so that I could compare the size of the resulting binary once compiled to my own solution, archived as ex1_10-5.c (ex1-10.5). The resulting binary, as compiled with GCC, was 136 lines long, 2 lines shorter than my own. Challenge failed :sigh:. Good exercise, though; I'll come back to this and study why later. --- KNR C/knrc-pseudowc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 KNR C/knrc-pseudowc.c diff --git a/KNR C/knrc-pseudowc.c b/KNR C/knrc-pseudowc.c new file mode 100644 index 0000000..7c410bc --- /dev/null +++ b/KNR C/knrc-pseudowc.c @@ -0,0 +1,24 @@ +#include + +#define IN 1 +#define OUT 0 + +int main(){ + int c, nl, nw, nc, state; + + state = OUT; + nl = nw = nc = 0; + while ((c = getchar()) != EOF){ + ++nc; + 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); + return 0; +}