diff --git a/makefile b/makefile index 4a0450b..4648c2c 100644 --- a/makefile +++ b/makefile @@ -28,3 +28,6 @@ build: $(SRC) format: $(SRC) $(FORMATTER) $(SRC) + +test: $(OUTPUT) + /bin/echo -e "123\n45 67" | ./$(OUTPUT) diff --git a/wc b/wc index c592776..6d987bf 100755 Binary files a/wc and b/wc differ diff --git a/wc.c b/wc.c index a12f360..a154f59 100644 --- a/wc.c +++ b/wc.c @@ -1,10 +1,23 @@ -#include #include +#include // read, isatty -int main(){ - char buffer[1]; - while(read(0,buffer,sizeof(buffer)) > 0){ - printf("%c", buffer[0]); - } - return 0; +// STDIN_FILENO +int process_fp(FILE* fp) +{ + char buffer[1]; + while (read(0, buffer, sizeof(buffer)) > 0) { + printf("%c", buffer[0]); + } + return 0; +} + +int main(int argc, char** argv) +{ + // + if (!isatty(STDIN_FILENO)) { // check if stdin is coming from terminal or pipeline + return process_fp(STDIN_FILENO); + } else if(argc > 1){ + printf("To do"); + } + return 0; }