k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit fecba9abf1a7eb5458665a1f2a7ebb0b55fbc005
parent dcf829ab3eeebd17f06ad5c4aea43de3b18fbdf4
Author: qorg11 <qorg@vxempire.xyz>
Date:   Thu, 30 Jul 2020 14:07:24 +0200

Almost done wc
only pick from stdin if no file given. but all flags are working!

Diffstat:
Msrc/wc.c | 27+++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/wc.c b/src/wc.c @@ -45,7 +45,7 @@ main(int argc, char *argv[]) { int c; int show_lines, show_words, show_bytes; - + show_lines = show_words = show_bytes = 1; struct wc_values data; /* Process arguments */ @@ -54,13 +54,13 @@ main(int argc, char *argv[]) switch(c) { case 'l': - show_lines = 1; + show_lines = 0; break; case 'w': - show_words = 1; + show_words = 0; break; case 'c': - show_bytes = 1; + show_bytes = 0; break; } } @@ -72,14 +72,17 @@ main(int argc, char *argv[]) data = wc(fopen(argv[i],"r")); else data = wc(stdin); - /* printf("%i %i %i\n",show_lines, show_bytes, - show_words); */ - if(show_lines) - printf("%i ",data.lines); - if(show_words) - printf("%i ",data.words); - if(show_bytes) - printf("%i",data.bytes); + if(show_lines && show_words && show_bytes) + printf("%i %i %i",data.lines, data.words, data.bytes); + else + { + if(!show_lines) + printf("%i ",data.lines); + if(!show_words) + printf("%i ",data.words); + if(!show_bytes) + printf("%i ",data.bytes); + } } printf("\n"); }