k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit 371c5f0803649496ebb1023dbbe0ac881a43fc26
parent c0935a1b07fc6ebd68a19af9c15f035bc4a604fa
Author: qorg11 <qorg@vxempire.xyz>
Date:   Tue, 28 Jul 2020 14:26:08 +0200

What the fuck is this

Diffstat:
Msrc/wc.c | 52++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 44 insertions(+), 8 deletions(-)

diff --git a/src/wc.c b/src/wc.c @@ -1,9 +1,24 @@ #include <stdio.h> #include <ctype.h> +#include <getopt.h> +#include <stdlib.h> -void +struct wc_values +{ + int lines; + int bytes; + int words; +}; + +struct wc_values wc(FILE *file) { + if(file == NULL) + { + fprintf(stderr,"error\n"); + exit(1); + } + struct wc_values foobar; char c; int newlines, spaces, bytes = 0; newlines = spaces = bytes = 0; @@ -15,22 +30,43 @@ wc(FILE *file) if(isspace(c)) spaces++; } - printf("%i %i %i\n",newlines,spaces,bytes); + foobar.bytes = bytes; + foobar.lines = newlines; + foobar.words = spaces; + + // printf("%i %i %i\n",newlines,spaces,bytes); fclose(file); + return foobar; } int main(int argc, char *argv[]) { + int c = getopt(argc, argv, "clw"); + struct wc_values data; if (argc == 1) - wc(stdin); + data = wc(stdin); else { - for(int i = 1; i<argc;i++) - { - wc(fopen(argv[i],"r")); - } - + for(int i = optind; i<argc;i++) + { + data = wc(fopen(argv[i],"r")); + switch(c) + { + case 'c': + printf("%i\n",data.bytes); + break; + case 'l': + printf("%i\n",data.lines); + break; + case 'w': + printf("%i\n",data.words); + break; + default: + printf("%i %i %i\n",data.lines,data.words,data.bytes); + } + } + } return 0; }