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:
parent
313e4aaa3b
commit
2523043172
1 changed files with 24 additions and 0 deletions
24
KNR C/knrc-pseudowc.c
Normal file
24
KNR C/knrc-pseudowc.c
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue