Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. int word_count(const char *filename)
  2. {
  3. FILE *f = fopen(filename, "r");
  4. if(!f) return -1;
  5. int counter = 0;
  6. char ch;
  7. char prev = '\0';
  8. int word;
  9. while((ch = fgetc(f)) != EOF) {
  10. if (isspace(ch) != 0 && isspace(prev) == 0) {
  11. counter++;
  12. word++;
  13. }
  14. }
  15. if(counter != 0) word++;
  16. return word;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement