fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int blanks, tabs, newlines;
  6. int c;
  7. int done = 0;
  8. int lastchar = 0;
  9.  
  10. blanks = 0;
  11. tabs = 0;
  12. newlines = 0;
  13.  
  14. while(done == 0)
  15. {
  16. c = getchar();
  17.  
  18. if(c == ' ')
  19. ++blanks;
  20.  
  21. if(c == '\t')
  22. ++tabs;
  23.  
  24. if(c == '\n')
  25. ++newlines;
  26.  
  27. if(c == EOF)
  28. {
  29. if(lastchar != '\n')
  30. {
  31. ++newlines; /* this is a bit of a semantic stretch, but it copes
  32.   * with implementations where a text file might not
  33.   * end with a newline. Thanks to Jim Stad for pointing
  34.   * this out.
  35.   */
  36. }
  37. done = 1;
  38. }
  39. lastchar = c;
  40. }
  41.  
  42. printf("Blanks: %d\nTabs: %d\nLines: %d\n", blanks, tabs, newlines);
  43. return 0;
  44. }
Success #stdin #stdout 0s 2296KB
stdin
And then there were none.
	- Christie, Agatha -
stdout
Blanks: 7
Tabs: 1
Lines: 2