Guest User

Untitled

a guest
Dec 7th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. /* word counting */
  2.  
  3. #include <stdio.h>
  4.  
  5. #define IN 1 // inside a word
  6. #define OUT 0 // outside a word
  7.  
  8.  
  9. int main (void)
  10. {
  11. int c, n1, nw, nc, state;
  12.  
  13. state = OUT;
  14. n1 = nw = nc = 0;
  15. while ((c = getchar()) != EOF)
  16. {
  17. ++nc;
  18. if ( c == '\n')
  19. ++n1;
  20. if ( c == ' ' || c == '\n' || c == '\t')
  21. state = OUT;
  22. else if (state == OUT)
  23. {
  24. state = IN;
  25. ++nw;
  26. }
  27. }
  28.  
  29. printf (" %d %d %d\n", n1, nw, nc);
  30. return 0;
  31. }
Add Comment
Please, Sign In to add comment