diff --git a/src/wc.c b/src/wc.c index 587640b..b983e57 100644 --- a/src/wc.c +++ b/src/wc.c @@ -45,41 +45,44 @@ main(int argc, char *argv[]) { int c; int show_lines, show_words, show_bytes; - show_lines = show_words = show_bytes = 0; + struct wc_values data; /* Process arguments */ while((c = getopt(argc,argv,"lwc")) > 0) { switch(c) - { - case 'l': - show_lines = 1; - break; - case 'w': - show_words = 1; - break; - case 'c': - show_bytes = 1; - break; - default: - show_lines = show_words = show_bytes = 1; - } + { + case 'l': + show_lines = 1; + break; + case 'w': + show_words = 1; + break; + case 'c': + show_bytes = 1; + break; + } } for(int i = optind; i 1) - { - data = wc(fopen(argv[i],"r")); - if(show_lines) - printf("%i ",data.lines); - if(show_words) - printf("%i ",data.words); - if(show_bytes) - printf("%i",data.words); - } - + { + if(argc > i) + 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); + } + printf("\n"); } - printf("\n"); + return 0; }