1 /* 1-16. Revise the main routine of the longest-line program so it will
2 * correctly print the length of arbitrarily long input lines, and as much
3 * as possible of the text.
6 /* MAXLINE has been reduced for easier testing */
10 int getlin(char line[], int maxline);
11 void copy(char to[], char from[]);
15 int len; /* current line length */
16 int max; /* maximum length seen so far */
17 char line[MAXLINE]; /* current input line */
18 char longest[MAXLINE]; /* longest line saved here */
21 while ((len = getlin(line, MAXLINE)) > 0)
26 if (max > 0) /* there was a line */
27 printf("%d chars: %s", max, longest);
31 int getlin(char s[], int lim)
35 for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
42 while ((c=getchar())!=EOF && c!='\n')
47 void copy(char to[], char from[])
51 while ((to[i] = from[i]) != '\0')