diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/toilet.c | 13 | 
1 files changed, 5 insertions, 8 deletions
diff --git a/src/toilet.c b/src/toilet.c index aab9dcc..717afa4 100644 --- a/src/toilet.c +++ b/src/toilet.c @@ -98,22 +98,19 @@ static size_t count_lines(char *fname, FILE *f) {  static size_t count_words(FILE *f) {  #define BUF_SIZE 4096 -    size_t nwords = 0; -  static char buf[BUF_SIZE];    while (!feof(f)) { +    static char buf[BUF_SIZE];      const size_t n = fread(buf, 1, BUF_SIZE, f); -#define IN(i) (i < n) -    for (size_t i = 0; IN(i);) { +    // (c) Tom Forging +    for (size_t i = 0; i<n;) {        size_t previ = i; -      while (IN(i) && !isspace(buf[i])) i++; +      while (i<n && !isspace(buf[i])) i++;        nwords += i != previ; -      while (IN(i) && isspace(buf[i])) i++; +      while (i<n && isspace(buf[i])) i++;      } -#undef IN -    }    rewind(f);  | 
