You did not specify what goes wrong, but my guess it that the program never stops and prints the longest string entered.
You set the program to stop reading lines when
getline
returns 0, however if you look at your
getline
you will see that it always stores the enter in it. This means that for an empty string the length is 1 and not 0.
So if you replace
while( (len=getline(line, MAXLINE))>0)
with
while( (len=getline(line, MAXLINE))>1)
you should get your expected result.