Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat countwords.c
- #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);
- }
- $ gcc-9 -Wall -o countwords countwords.c
- $ cat countwords.c | ./countwords
- 24 74 371
- $ ./countwords < countwords.c
- 24 74 371
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement