Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<ctype.h>
  3.  
  4. int wordcount()
  5. {
  6. int c;
  7. int word_cnt=0;
  8. int char_cnt=0;
  9. int lines_cnt=1;
  10. while((c=getchar() )!=EOF)
  11. { char_cnt++;
  12. if(isspace(c))
  13. { if( !isspace((c=getchar())))
  14. word_cnt++;
  15. ungetc(c, stdin);
  16. }
  17. else if(c=='\n')
  18. lines_cnt++;
  19. }
  20. printf("No. of chars: %i, No. of words:%i, No. of lines:%i", char_cnt, word_cnt,lines_cnt);
  21.  
  22. }
  23.  
  24.  
  25.  
  26.  
  27. int main()
  28. {
  29.  
  30. wordcount();
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement