diff options
author | Manoj Srivastava <srivasta@debian.org> | 2016-07-29 18:07:24 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2016-07-29 18:07:24 -0700 |
commit | f1d010bed8760aa87f9c72eded97d4d9b98cc620 (patch) | |
tree | 439628ed03b3b68404b7198883f993d1ef2b6753 /examples/fastwc/mywc.c |
Import flex_2.6.1.orig.tar.gz
[dgit import orig flex_2.6.1.orig.tar.gz]
Diffstat (limited to 'examples/fastwc/mywc.c')
-rw-r--r-- | examples/fastwc/mywc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/fastwc/mywc.c b/examples/fastwc/mywc.c new file mode 100644 index 0000000..b07d5f0 --- /dev/null +++ b/examples/fastwc/mywc.c @@ -0,0 +1,26 @@ +/* A simple but fairly efficient C version of the Unix "wc" tool */ + +#include <stdio.h> +#include <ctype.h> + +main() +{ + int c, cc = 0, wc = 0, lc = 0; + FILE *f = stdin; + + while ((c = getc(f)) != EOF) { + ++cc; + if (isgraph(c)) { + ++wc; + do { + c = getc(f); + if (c == EOF) + goto done; + ++cc; + } while (isgraph(c)); + } + if (c == '\n') + ++lc; + } +done: printf( "%8d%8d%8d\n", lc, wc, cc ); +} |