diff --git a/wc b/wc index 39b027f..3181350 100755 Binary files a/wc and b/wc differ diff --git a/wc.c b/wc.c index 4e4d423..db4797a 100644 --- a/wc.c +++ b/wc.c @@ -5,9 +5,24 @@ int process_fn(int fn) { char c[1]; + int seen_word=0; + int seen_sep=0; + int num_words = 0; while (read(fn, c, sizeof(c)) > 0) { - printf("%c", c[0]); + if(*c == '\n' || *c == ' ' || *c == '\t'){ + seen_sep = 1; + } else { + seen_word = 1; + } + if(seen_word && seen_sep){ + num_words++; + seen_sep = seen_word = 0; + } } + if(seen_word){ + num_words++; + } + printf("%i\n",num_words); return 0; }