1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-11-10 00:30:35 +00:00

Exercise 1-16. Print arbitrarily long input lines

This commit is contained in:
Kris Lamoureux 2021-11-29 22:53:44 -05:00
parent 9fd4d3db68
commit f254c6e67e
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

View File

@ -9,15 +9,23 @@ main()
{ {
int len; int len;
int max; int max;
int c;
char line[MAXLINE]; char line[MAXLINE];
char longest[MAXLINE]; char longest[MAXLINE];
max = 0; 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) { if (len > max) {
max = len; max = len;
copy(longest, line); copy(longest, line);
} }
}
if (max > 0) if (max > 0)
printf("%s", longest); printf("%s", longest);
return 0; return 0;