K&R C Program Exercise 1-17

K and R solution Exercise 1-17,to print all input lines that are longer than 80 characters. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include "stdio.h"
#define MAXINLINE 1000 /* maximum line sizes defined*/
#define LONGLINESIZE 80 /* longer line defined as 80 */
int get_lines(char line[], int maxline);
/*print lines longer than LONGLINESIZE */
main()
{
int len; /*current line length */
char line[MAXINLINE];/* current input line */
while((len=get_lines(line,MAXINLINE))>0)
if(len> LONGLINE)
printf("%s", line);
return 0;

}

/* getline: read a line into s, return length */
int get_lines(char s[], int line)
{
int c, i, j;

for(i = 0, j = 0; (c = getchar())!=EOF && c != 'n'; ++i)
{
if(i < line - 1)
{
s[j++] = c;
}
}
if(c == 'n')
{
if(i <= line - 1)
{
s[j++] = c;
}
++i;
}
s[j] = '