commit dea33a4032df1df25dee47a27adbbce8f092b6af
parent d4747ae74f1eea47c4720822161e1c652a237279
Author: Tyler Clark <tyler.clark@foxide.xyz>
Date: Sun, 9 Feb 2025 21:42:28 -0500
Working on wc.c, and correcting a comment in head.c
Diffstat:
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/head.c b/src/head.c
@@ -1,4 +1,4 @@
-/* Terrible implementation of the false core util */
+/* Terrible implementation of the head core util */
/* For license infomration see the LICENSE file included in this repo */
#include<stdio.h>
#include<stdlib.h>
diff --git a/src/wc.c b/src/wc.c
@@ -1,4 +1,4 @@
-/* wc utility from TCU */
+/* Terrible implementation of the wc core util */
/* for licensing information please see included LICENSE file */
/* The WC utility lists the number of lines, words, and bytes contained in each input file */
@@ -13,19 +13,28 @@
/* TODO: -w The number of words in each input file is written to the standard output. */
#include<stdio.h>
+#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[]) {
/* Prep stuff */
FILE *fp;
char ch;
- /* relatively setting the counters for lines, words, and bytes to zero */
- int lValue = 0, wValue = 0, bValue = 0;
+ /* Initilizing values for counters */
+ int lValue, wValue, bValue;
+ /* Initializing values for totals */
+ int lTotal = 0, wTotal = 0, bTotal = 0;
/* This will be used to iterate through files */
- int i = 0;
+ int i = 1;
+
+ int lineCount = strcmp(argv[1], "-l");
+
/* rough draft of basic idea */
- for (i = 0; i <= argc; i++) {
+ for (i = 1; i < argc; i++) {
+ lValue = 0;
+ wValue = 0;
+ bValue = 0;
fp = fopen(argv[i], "r");
while((ch = fgetc(fp)) != EOF) {
if (ch == '\n') {
@@ -44,7 +53,12 @@ int main(int argc, char *argv[]) {
}
bValue++;
}
- printf("%4d%5d%5d%8s\n", lValue, wValue, bValue, argv[1]);
+ printf("%4d%5d%5d%10s\n", lValue, wValue, bValue, argv[i]);
+ lTotal = lTotal + lValue;
+ wTotal = wTotal + wValue;
+ bTotal = bTotal + bValue;
+ fclose(fp);
}
+ if (argc > 2) printf("%4d%5d%5d Total\n", lTotal, wTotal, bTotal);
return 0;
}