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.

This commit is contained in:
Reina Harrington-Affine 2025-08-16 02:07:42 +00:00
parent 313e4aaa3b
commit 2523043172

24
KNR C/knrc-pseudowc.c Normal file
View file

@ -0,0 +1,24 @@
#include <stdio.h>
#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;
}