I was trying an exercise in K&R which asks to write a program which reads a set of text line and prints the longest line.

I writing along the lines of something like this;

```
define a string of characters
write a function that marks the length of line until there's a newline
when encountered newline, the function again repeats
keep copying length to a variable if the length of newline is greater
copy the string (if of greater length) to another string
print the last copied string

```

I tried writing the function this mark the length which is certainly wrong

```
int getlength(char str[],int lim)
{
    int length ,c;
    c = getchar();
    while((c=getchar())!= '\n')
    {
        for (length=0; length < lim -1; length++)
            c = str[length];
    }
    return length;
}

```

Can anyone suggest me how to write the getlength function. I am not asking for the code but instead the psuedocode would be very helpful.