count-btn.c 474 B

1234567891011121314151617181920212223242526
  1. #include <stdio.h>
  2. int
  3. main () {
  4. //Variables for blanks, tabs, and newlines
  5. int b, t, n = 0;
  6. int c;
  7. // Loop through the input, and add up all of
  8. // the blanks, tabs, and newlines
  9. while ((c = getchar ()) != EOF) {
  10. switch (c) {
  11. case '\n':
  12. n += 1;
  13. break;
  14. case '\t':
  15. t += 1;
  16. break;
  17. case ' ':
  18. b += 1;
  19. break;
  20. }
  21. }
  22. // print the results
  23. printf("There are %d blanks, %d tabs, and %d newlines.\n", b, t, n);
  24. }