diff options
author | Ferass El Hafidi <vitali64pmemail@protonmail.com> | 2023-03-02 17:57:19 +0100 |
---|---|---|
committer | Ferass El Hafidi <vitali64pmemail@protonmail.com> | 2023-03-02 17:57:19 +0100 |
commit | 5f420737d7d7685cf7dce0148ba2e91276aa4b06 (patch) | |
tree | dcaaace72c31bc631f9eb4b0c864254dc6ee9359 | |
parent | 67812f624013eaa6f39baea397be976ad8994700 (diff) | |
download | fases-5f420737d7d7685cf7dce0148ba2e91276aa4b06.tar.gz fases-5f420737d7d7685cf7dce0148ba2e91276aa4b06.zip |
core/wc: Fix bug -- see description
wc used to always return 'total %d %d %d %s\n' (in
pseudo-printf here) regardless of if one or multiple
files were specified.
Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
-rw-r--r-- | core/wc.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -37,6 +37,7 @@ int main(int argc, char *const argv[]) { } for (int i = 0; i != argc; i++) { + words = 0; bytes = 0; newlines = 0; file = fopen(argv[i], "r"); if (errno) return errprint(argv0, argv[i], errno); while ((length = getline(&line, &len_getd, file)) != -1) { @@ -57,7 +58,6 @@ int main(int argc, char *const argv[]) { total_bytes += bytes; total_words += words; total_newlines += newlines; - words = 0; bytes = 0; newlines = 0; } if (total_bytes != bytes) { if (param['l']) printf("%zu ", total_newlines); |