summaryrefslogtreecommitdiffstats
path: root/main.c
blob: 6f91ed7043343f722e29c9abc37342fc59c57bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}