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:
parent
9fd4d3db68
commit
f254c6e67e
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user