Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int word_count(const char *filename)
- {
- FILE *f = fopen(filename, "r");
- if(!f) return -1;
- int counter = 0;
- char ch;
- char prev = '\0';
- int word;
- while((ch = fgetc(f)) != EOF) {
- if (isspace(ch) != 0 && isspace(prev) == 0) {
- counter++;
- word++;
- }
- }
- if(counter != 0) word++;
- return word;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement