further progress.
This commit is contained in:
parent
443b7503f9
commit
727a6f6485
17
wc.c
17
wc.c
|
@ -5,9 +5,24 @@
|
||||||
int process_fn(int fn)
|
int process_fn(int fn)
|
||||||
{
|
{
|
||||||
char c[1];
|
char c[1];
|
||||||
|
int seen_word=0;
|
||||||
|
int seen_sep=0;
|
||||||
|
int num_words = 0;
|
||||||
while (read(fn, c, sizeof(c)) > 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user