fork download
  1. #include <stdio.h>
  2. #define IN 1 /* inside a word */
  3. #define OUT 0 /* outside a word */
  4. /* count lines, words, and characters in input */
  5. main()
  6. {
  7. int c, nl, nw, nc, state;
  8. state = OUT;
  9. nl = nw = nc = 0;
  10. while ((c = getchar()) != EOF) {
  11. ++nc;
  12. if (c == '\n')
  13. ++nl;
  14. if (c == ' ' || c == '\n' || c == '\t')
  15. state = OUT;
  16. else if (state == OUT) {
  17. state = IN;
  18. ++nw;
  19. }
  20. }
  21. printf("%d %d %d\n", nl, nw, nc);
  22. }
Success #stdin #stdout 0s 9416KB
stdin
Standard input is empty
stdout
0 0 0