1
0
mirror of https://github.com/krislamo/knrc.git synced 2025-09-11 16:39:28 +00:00

Exercise 1-16. Print arbitrarily long input lines

This commit is contained in:
2021-11-29 22:53:44 -05:00
parent 9fd4d3db68
commit f254c6e67e

View File

@@ -9,15 +9,23 @@ main()
{
int len;
int max;
int c;
char line[MAXLINE];
char longest[MAXLINE];
max = 0;
while((len = getline(line, MAXLINE)) > 0)
while((len = getline(line, MAXLINE)) > 0) {
if (line[len-1] != '\n') {
while ((c=getchar())!=EOF && c!='\n')
++len;
if (c == '\n')
++len;
}
if (len > max) {
max = len;
copy(longest, line);
}
}
if (max > 0)
printf("%s", longest);
return 0;