summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorGentoo <installgentoo@endianness.com>2021-03-27 10:12:21 +1100
committerGentoo <installgentoo@endianness.com>2021-03-27 10:12:21 +1100
commit45b8d40d402242ab60103f6c06535c3785e03c28 (patch)
treefbc44950decf839446b3574920981878bd506be8 /main.c
downloadline-restrictions-master.tar.gz
line-restrictions-master.tar.bz2
line-restrictions-master.zip
initial commitHEADmaster
Diffstat (limited to 'main.c')
-rw-r--r--main.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..6f91ed7
--- /dev/null
+++ b/main.c
@@ -0,0 +1,38 @@
+//Print lines from stdin if they are longer than 80 and shorter than 256
+#include <stdio.h>
+
+#define MAXLINE 256
+
+int main(void)
+{
+char buff;
+char array[MAXLINE];
+
+unsigned short int length = 0;
+//unsigned short int loop;
+while ((buff = getchar()) != EOF)
+{
+if (length == MAXLINE){length = 0; goto skip;}//if we are about to overflow, reset and skip
+
+array[length] = buff;//write the char to the array
+
+if ((buff == '\n') && (length <= 80))//if there's a newline, and the lines length is shorter or equal to 80, reset and don't print
+{
+length = 0;
+goto skip;
+}
+
+if ((buff == '\n') && (length > 80))//if there's a newline and length is over 80, print the string
+{
+array[length+1] = '\0';//add a NULL char to end of input so any old values aren't printed
+printf("%s", array);
+length = 0;
+goto skip;
+}
+
+++length;
+skip: ;
+}
+
+return 0;
+}