i have to count words of 3 files. The results should be 138, 166, 148 but they are 138, 165, 147. Can someone explain/help?
int countwords(const char* filename) {
char z;
int inw = 0;
int words = 0;
FILE *ed;
ed = fopen(filename, "r");
while ((z = fgetc(ed)) != EOF ){
if (z == ' ' || z == '\n' || z == '\t' || z == '\0') {
if(inw) {
inw = 0;
words++;
}
} else {
inw = 1;
}
}
fclose(ed);
return words;
}```