diff options
Diffstat (limited to 'wc.c')
-rw-r--r-- | wc.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/wc.c b/wc.c new file mode 100644 index 0000000..e1445e1 --- /dev/null +++ b/wc.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +int main() { + long nc, nw, nl; + int c; + char inWord; + nc = nw = nl = 0; + while ((c = getchar()) != EOF) { + if (c == '\n') ++nl; + if (c == ' ' || c == '\t' || c == '\n') inWord=0; + else if (inWord == 0) { + inWord = 1; + ++nw; + } + ++nc; + } + printf(" %ld %ld %ld\n", nl, nw, nc); + return 0; +} |