Advertisement
khalfella

c_ch01_ex08.c

Sep 20th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. /*
  2. * Exercise 1-8.
  3. * Write a program to count blanks, tabs, and newlines.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. main() {
  9. int c;
  10. long blanks, tabs, lines;
  11.  
  12. blanks = tabs = lines = 0;
  13.  
  14. while ((c = getchar()) != EOF) {
  15. if (c == ' ')
  16. ++blanks;
  17. if (c == '\t')
  18. ++tabs;
  19. if (c == '\n')
  20. ++lines;
  21. }
  22.  
  23. printf("blanks = %ld, tabs = %ld, newlines = %ld\n",
  24. blanks, tabs, lines);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement