summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors a m <samuel@yakubos.org>2026-06-07 02:17:38 +0100
committers a m <samuel@yakubos.org>2026-06-07 02:17:38 +0100
commitf6705daa5ef7be2deb1e1a183e92417d9770f99c (patch)
tree130fc1cdba5d3296adb95fbb6b6ca224ee9b0ea3
parent3dbe54853c4733bbe5ff58a6403d1759e921bdc3 (diff)
Remove silly script and switch to long instead of ints
-rw-r--r--README.md6
-rwxr-xr-xbuild.sh7
-rw-r--r--stats.c36
3 files changed, 24 insertions, 25 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2aa95bb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+# Stats counter
+compile with `make`
+
+usage: stats <numbers>
+
+you must include multiple numbers or there is no use
diff --git a/build.sh b/build.sh
deleted file mode 100755
index e980568..0000000
--- a/build.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-clear
-
-vim stats.c
-
-make
diff --git a/stats.c b/stats.c
index fa69715..335346f 100644
--- a/stats.c
+++ b/stats.c
@@ -14,9 +14,9 @@ void help(){
}
/* ADDING UP ALL THE VALUES */
-int sigma(int argc, char * argv[]) {
+long sigma(int argc, char * argv[]) {
char *endptr;
- int sum = 0;
+ long sum = 0;
for (int i = 1; i < argc; i++) {
@@ -36,12 +36,12 @@ float average(int n, int sum) {
}
/* FINDING THE MIN/MAX/DIFFERENCE */
-int range(int argc, char * argv[], enum MODE mode) {
- int low = strtol(argv[1], NULL, 10);
- int high = low;
+long range(int argc, char * argv[], enum MODE mode) {
+ long low = strtol(argv[1], NULL, 10);
+ long high = low;
for (int i = 1; i < argc; i++) {
- int val = strtol(argv[i], NULL, 10);
+ long val = strtol(argv[i], NULL, 10);
if (val > high) high = val;
if (low > val) low = val;
}
@@ -63,19 +63,19 @@ int main(int argc, char * argv[]) {
help();
}
- int n = argc - 1; /* this is how many numbers there are */
- int sum = sigma(argc, argv); /* sigma means adding them all together */
- float mean = average(n, sum); /* the sum divided by the however many numbers there are */
- int min = range(argc, argv, MODE_MIN); /* Using enums here to use words instead of numbers */
- int max = range(argc, argv, MODE_MAX);
- int diff = range(argc, argv, MODE_DIFF);
+ long n = argc - 1; /* this is how many numbers there are */
+ long sum = sigma(argc, argv); /* sigma means adding them all together */
+ float mean = average(n, sum); /* the sum divided by the however many numbers there are */
+ long min = range(argc, argv, MODE_MIN); /* Using enums here to use words instead of numbers */
+ long max = range(argc, argv, MODE_MAX);
+ long diff = range(argc, argv, MODE_DIFF);
/* align text left for 6 and 12 right */
- printf("%-6s %12d\n", "num:", n);
- printf("%-6s %12d\n", "sum:", sum);
- printf("%-6s %12.3f\n", "mean:", mean);
- printf("%-6s %12d\n", "min:", min);
- printf("%-6s %12d\n", "max:", max);
- printf("%-6s %12d\n", "range:", diff);
+ printf("%-6s %12ld\n", "num:", n);
+ printf("%-6s %12ld\n", "sum:", sum);
+ printf("%-6s %12.3f\n", "mean:", mean);
+ printf("%-6s %12ld\n", "min:", min);
+ printf("%-6s %12ld\n", "max:", max);
+ printf("%-6s %12ld\n", "range:", diff);
}