Exercise 1-17 from the book The C Programming Language: 2nd Edition, K&R
Full description: Write a program to print all input lines that are longer than 80 characters.
#include <stdio.h>
#define MAX_ARRAYCHARACTERS 1000
#define MIN_CHARACTERS 80
int main(void){
int currchar, // current character being read
currlinelen = 0; // how many characters in a line
char characters[MAX_ARRAYCHARACTERS]; // holds all the characters
while( ( currchar = getchar() ) != EOF ){
characters[currlinelen] = currchar;
++currlinelen;
if(currchar == '\n'){ // if there is a new line
if(currlinelen >= MIN_CHARACTERS){ // if the total length of characters of this line is higher than 80
puts("LINE WITH 80+ CHARACTERS: ");
for(int thischar = 0; thischar < currlinelen; ++thischar) // print all the characters that were in that line
putchar(characters[thischar]);
}
currlinelen = 0;
}
}
return 0;
}