aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFerass El Hafidi <vitali64pmemail@protonmail.com>2023-03-02 17:57:19 +0100
committerFerass El Hafidi <vitali64pmemail@protonmail.com>2023-03-02 17:57:19 +0100
commit5f420737d7d7685cf7dce0148ba2e91276aa4b06 (patch)
treedcaaace72c31bc631f9eb4b0c864254dc6ee9359
parent67812f624013eaa6f39baea397be976ad8994700 (diff)
downloadfases-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.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/wc.c b/core/wc.c
index 9146b8b..650a555 100644
--- a/core/wc.c
+++ b/core/wc.c
@@ -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);