samir82show

c_ch01_ex08.c

Sep 22nd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. /*Exercise 1-8. Write a program to count blanks, tabs, and newlines*/
  2.  
  3. #include <stdio.h>
  4. int main()
  5. {
  6. int nb, nt, nl, c;
  7. nb = nt = nl = 0;
  8. while ((c = getchar()) != EOF) {
  9. if (c == ' ') nb++;
  10. else if (c == '\t') nt++;
  11. else if (c == '\n') nl++;
  12. }
  13. printf ("nb = %d\t nt = %d\t nl = %d", nb, nt, nl);
  14. return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment