make format

This commit is contained in:
NunoSempere 2023-09-09 00:07:22 +02:00
parent 2009c18381
commit 33c4972b3d

14
ww.c
View File

@ -5,13 +5,13 @@
int process_fn(int fn) int process_fn(int fn)
{ {
char c[1]; char c[1];
int seen_word=0; int seen_word = 0;
int seen_sep_after_word=0; int seen_sep_after_word = 0;
int num_words = 0; int num_words = 0;
while (read(fn, c, sizeof(c)) > 0) { while (read(fn, c, sizeof(c)) > 0) {
if(*c != '\n' && *c != ' ' && *c != '\t'){ if (*c != '\n' && *c != ' ' && *c != '\t') {
seen_word = 1; seen_word = 1;
} else if(seen_word) { } else if (seen_word) {
seen_sep_after_word = 1; seen_sep_after_word = 1;
} else { } else {
// see a separator, but haven't seen a word: do nothing // see a separator, but haven't seen a word: do nothing
@ -19,15 +19,15 @@ int process_fn(int fn)
// instead of seen_sep_after_word? // instead of seen_sep_after_word?
// test with: $ echo " x x" | ./wc // test with: $ echo " x x" | ./wc
} }
if(seen_word && seen_sep_after_word){ if (seen_word && seen_sep_after_word) {
num_words++; num_words++;
seen_sep_after_word = seen_word = 0; seen_sep_after_word = seen_word = 0;
} }
} }
if(seen_word){ if (seen_word) {
num_words++; num_words++;
} }
printf("%i\n",num_words); printf("%i\n", num_words);
return 0; return 0;
} }