wc

Count words in <50 lines of C
Log | Files | Refs | README

commit c7520331211f54c090569f88279d811e367b1acb
parent 4a9ab4f9f31ff84bfcff7f70149264d82e2b2fbf
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Fri,  8 Sep 2023 23:07:49 +0200

take a filenum instead of a file pointer.

Diffstat:
Mwc | 0
Mwc.c | 7+++----
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/wc b/wc Binary files differ. diff --git a/wc.c b/wc.c @@ -2,10 +2,10 @@ #include <unistd.h> // read, isatty // STDIN_FILENO -int process_fp(FILE* fp) +int process_fp(int filenum) { char buffer[1]; - while (read(0, buffer, sizeof(buffer)) > 0) { + while (read(filenum, buffer, sizeof(buffer)) > 0) { printf("%c", buffer[0]); } return 0; @@ -13,8 +13,7 @@ int process_fp(FILE* fp) int main(int argc, char** argv) { - // - if (!isatty(STDIN_FILENO)) { // check if stdin is coming from terminal or pipeline + if (!isatty(STDIN_FILENO)) { return process_fp(STDIN_FILENO); } else if(argc > 1){ printf("To do");