about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoraabacchus <ben@bvnf.space>2021-05-19 02:05:53 +0100
committeraabacchus <ben@bvnf.space>2021-05-19 02:05:53 +0100
commit58908e6c604814e325d749228ad834e9fdc20a7f (patch)
treea3c38a1d8653f39a505ece595e814b1a6ac6aff6
parent6740296c1955baf26c77b0037de72a19862dfe8a (diff)
downloadkandr-58908e6c604814e325d749228ad834e9fdc20a7f.tar.gz
1-13: add usage
-rw-r--r--1.6.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/1.6.c b/1.6.c
index 1d4beef..41004ad 100644
--- a/1.6.c
+++ b/1.6.c
@@ -1,7 +1,8 @@
 #include <stdio.h>
+
 #define OUTWORD 0
 #define INWORD  1
-#define MAXWORDLEN 20
+#define MAXWORDLEN 30
 
 int longest(const int *list) {
     int max = 0;
@@ -12,7 +13,14 @@ int longest(const int *list) {
     return max;
 }
 
-int main () {
+void usage() {
+    printf("print a histogram of the lengths of words in stdin (K&R ex 1-13)\n");
+    printf("    vertical axis is frequency\n");
+    printf("    horizontal axis is word length\n");
+}
+
+int main (int argc, char *argv[]) {
+    if (argc > 1) { usage(); return 0;}
 	int c, i, j, wordlen;
 	int ndigit[MAXWORDLEN] = {0};
     wordlen = 0;
@@ -48,4 +56,5 @@ int main () {
     for (j = 0; j < MAXWORDLEN; ++j)
         printf("%3d", j);
     printf("\n");
+    return 0;
 }